Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Can't compile: BadImageFormatException

Discussion in 'Editor & General Support' started by Jerware, Nov 20, 2013.

  1. Jerware

    Jerware

    Joined:
    May 15, 2012
    Posts:
    41
    I'm trying to compile a project for iOS using Unity 4.3 and am getting the following two errors:

    BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid.
    Mono.Cecil.PE.ImageReader.ReadImage ()
    Mono.Cecil.PE.ImageReader.ReadImageFrom (System.IO.Stream stream)
    Mono.Cecil.ModuleDefinition.ReadModule (System.IO.Stream stream, Mono.Cecil.ReaderParameters parameters)
    Mono.Cecil.ModuleDefinition.ReadModule (System.String fileName, Mono.Cecil.ReaderParameters parameters)
    Mono.Cecil.ModuleDefinition.ReadModule (System.String fileName)
    Mono.Cecil.AssemblyDefinition.ReadAssembly (System.String fileName)
    UnityEditor.AssemblyReferenceChecker.CollectReferences (System.String path, Boolean withMethods, Single progressValue, Boolean ignoreSystemDlls)
    UnityEditor.AssemblyReferenceChecker.GetScriptsHaveMouseEvents (System.String path)
    UnityEditor.HostView:OnGUI()

    ...and...

    !IsDirectoryCreated(kManagedDllsFolder)
    UnityEditor.HostView:OnGUI()

    The project was compiling fine yesterday, and I haven't made that many changes today. I've tried reinstalling Unity and deleting the /Temp folder, as well as changing the Api Compatibility Level from .NET 2.0 Subset to .NET 2.0, but nothing seems to work. Does anyone have an idea? I'm going nuts and would appreciate the help.
     
  2. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,562
    Hmm... this exception usually means that a DLL you're trying to access either isn't managed or is corrupt. Is there anything else that's been compiled in your project or maybe a 3rd party assembly that's compiled for a target (like x64 instead of Any CPU)?
     
  3. Jerware

    Jerware

    Joined:
    May 15, 2012
    Posts:
    41
    Thanks for the reply. It just got weirder. I created a new, empty project. It compiled. Then I created blank C# and JS scripts (leaving the default, empty functions), and hit build. I got the exact same error as above.

    I looked in Temp/StagingArea/Data/Managed, and both Assembly-CSharp.dll and Assembly-UnityScript.dll are Zero bytes(!). The same files in Library/ScriptAssemblies and 3KB and 2KB respectively. What is going on? Any ideas?
     
  4. Jerware

    Jerware

    Joined:
    May 15, 2012
    Posts:
    41
    Rebooted my QNAP NAS box where the project is stored. Seems to have solved the problem. Ugh.
     
  5. DreamEnder

    DreamEnder

    Joined:
    Apr 12, 2011
    Posts:
    190
    I'm getting the same error after updating Unity to 4.3.3f1. So frustrating.
     
  6. DreamEnder

    DreamEnder

    Joined:
    Apr 12, 2011
    Posts:
    190
    Does anyone know how to find what DLL is giving the error?
     
  7. phila666

    phila666

    Joined:
    Jul 30, 2013
    Posts:
    1
    I had this same problem in Unity 5.6, Google Cardboard 1.5, until I moved my project to the main drive of my mac. It failed with this error when building on a second partition of the drive.
     
    ledbetterman likes this.
  8. ledbetterman

    ledbetterman

    Joined:
    May 5, 2015
    Posts:
    80
    Wanted to report that I'm using Unity 5.6.1f1 on Windows 10, trying to build a Google Daydream app and I had to move my project onto my main drive. Trying to build from a secondary drive was giving me a "!IsDirectoryCreated(kManagedDllsFolder)" error with an IO exception related to the DLL.

    Moving it to C: drive fixed the issue.
     
    hrahaman likes this.
unityunity