Search Unity

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.
     
    kafloreshernandez likes this.
  2. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    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:
    191
    I'm getting the same error after updating Unity to 4.3.3f1. So frustrating.
     
  6. DreamEnder

    DreamEnder

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

    phila666

    Joined:
    Jul 30, 2013
    Posts:
    9
    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.
     
    ChoiNowGo and led_bet like this.
  8. led_bet

    led_bet

    Joined:
    May 5, 2015
    Posts:
    83
    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.
  9. uotsabchakma

    uotsabchakma

    Joined:
    Sep 17, 2019
    Posts:
    93
    It happens with this project for me. I have no idea to solve any corruption that is causing this error.
     
  10. uotsabchakma

    uotsabchakma

    Joined:
    Sep 17, 2019
    Posts:
    93
    I finally fixed this. May not work for everyone.
    I deleted Everything, without of (/keeping) Assets and Packages folder. And after opening again, the problem solved.
    I think there was a problem with the library folder. Something might had corrupted.
    Note that I also installed new version of Unity. But I think it has not effected my project so much.
    Again, might not work for all but it may help you.
     
    strongBearCeo and Ausername like this.
  11. kafloreshernandez

    kafloreshernandez

    Joined:
    Jul 31, 2023
    Posts:
    2
    I had this error too, I had my project in an SSD so I copied it to the main drive and now the project builds without errors.... The issue is now in Xcode saying 'Linker command failed with exit code 1 (use -v to see invocation)'

    Oh well one step at a time xD
     
  12. pnyxtr

    pnyxtr

    Joined:
    Oct 29, 2014
    Posts:
    14
    I don't have space on my main drive. Anyway to make builds work from external drive?