Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am getting System.BadImageFormatException: Invalid Image System.Runtime.InteropServices.RuntimeInformation.dll when running asp.net app using mono

Ask Question

My team has a web app we are supporting built using .net framework 4.6 I am trying to start the same app on my Linux machine (Ubuntu 20.04) using Mono and Jetbrains Rider. My Code compiles but when I try to open any page I get a runtime error System.BadImageFormatException: Invalid Image

Here is my stack trace:

System.BadImageFormatException: Invalid Image
File name: '/home/codemancystudio/drillstack-asp/Drillstack.Web/bin/System.Runtime.InteropServices.RuntimeInformation.dll'
  at (wrapper managed-to-native) System.Reflection.Assembly.LoadFrom(string,bool,System.Threading.StackCrawlMark&)
  at System.Reflection.Assembly.LoadFrom (System.String assemblyFile) [0x00002] in <a17fa1457c5d44f2885ac746c1764ea5>:0
  at System.Web.Compilation.AssemblyBuilder.ReferenceAssembly (System.Collections.Generic.Dictionary`2[TKey,TValue] moduleGuidCache, System.Collections.Generic.List`1[T] assemblies, System.String asmLocation) [0x00000] in <716e5fc6fa1b4b5db9a4701d451ead9c>:0
  at System.Web.Compilation.AssemblyBuilder.ReferenceAssemblies (System.Collections.Generic.Dictionary`2[TKey,TValue] moduleGuidCache, System.Collections.Generic.List`1[T] assemblies, System.Collections.Specialized.StringCollection references) [0x0001c] in <716e5fc6fa1b4b5db9a4701d451ead9c>:0
  at System.Web.Compilation.AssemblyBuilder.BuildAssembly (System.Web.VirtualPath virtualPath, System.CodeDom.Compiler.CompilerParameters options) [0x001f9] in <716e5fc6fa1b4b5db9a4701d451ead9c>:0
  at System.Web.Compilation.AssemblyBuilder.BuildAssembly (System.CodeDom.Compiler.CompilerParameters options) [0x00000] in <716e5fc6fa1b4b5db9a4701d451ead9c>:0
  at System.Web.Compilation.AppCodeAssembly.Build (System.String[] binAssemblies) [0x003be] in <716e5fc6fa1b4b5db9a4701d451ead9c>:0
  at System.Web.Compilation.AppCodeCompiler.Compile () [0x000a1] in <716e5fc6fa1b4b5db9a4701d451ead9c>:0
  at System.Web.HttpApplicationFactory.InitType (System.Web.HttpContext context) [0x0020f] in <716e5fc6fa1b4b5db9a4701d451ead9c>:0
  at System.Web.HttpApplicationFactory.GetApplication (System.Web.HttpContext context) [0x00018] in <716e5fc6fa1b4b5db9a4701d451ead9c>:0
  at System.Web.HttpRuntime.Process (System.Web.HttpWorkerRequest req) [0x00052] in <716e5fc6fa1b4b5db9a4701d451ead9c>:0

Edit 1

The machine I use has AMD A10 9700 as CPU, 16 GB DDR4 of RAM, Gigabyte A320M-S2H Motherboard. I tried setting the platform target to x86 and to x64 but by default, it is set to Any CPU.

https://www.codeproject.com/Questions/379478/System-BadImageFormatException-was-thrown might help you – Abdul Haseeb Aug 11, 2020 at 16:06 @Neil he is using Mono. That's a way to run .net framework apps on Linux that appeared prior to .Net Core. His question is valid, just not clear enough. On which machine was the assembly built? For which target was it built (32 or 64 bits)? – Anouar Aug 11, 2020 at 17:01 @Anouar Machine I use has AMD A10 9700 as CPU, 16 GB DDR4 of RAM, Gigabyte A320M-S2H Motherboard. I tried setting project architecture to x86 and to x64. – Nenad Andrejevic Aug 12, 2020 at 10:23

When .NET attempts to make use of a .dll or .exe that is, in some way, incompatible with the current common language runtime. What qualifies as an “incompatible common language runtime” can vary somewhat, but typically this means either the .NET version (1.1, 2.0, etc) OR the CPU type (32-bit vs 64-bit) of the various compiled assemblies do not match.

Ultimately, System.BadImageFormatExceptions are an indication of incompatible versioning. For many modern software applications, major versions of often include breaking compatibility issues, preventing backward compatibility with some aspects of previous versions. .NET assemblies (.dlls or .exes) are much the same, and attempting to make use of two different types of assemblies that contain incompatibilities will often generate a System.BadImageFormatException.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.