Please help, I've tried everything else I can think of to solve this problem.
And before you respond please note:
I have done everything I can from other questions on StackOverflow.com and else-ware on the web. Such as but not limited to: Changing the build configuration from: "Any CPU" to "x64" and even to "x86". And also changing the target build from .NET 4.0 to .NET 3.5 (This does not work as I am using System.Windows.Interactivity that requires .NET 4.0) So I'm rather stuck with .NET 4.0. So please don't give an answer telling me to do this as I have already tried various combinations of this.
I've got a project in VS2013 called TimersXP that is an open-source project on CodePlex.com: https://timersxp.codeplex.com/
It builds without any errors, but I'm getting a run-time exception: System.BadImageFormatException was unhandled Message: An unhandled exception of type 'System.BadImageFormatException' occurred in Unknown Module. Additional information: Could not load file or assembly 'TimersXP.exe' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
A little history, the project was originally .NET 3.5, but when I found I had to add System.Windows.Interactivity and that had to support .NET 4.0 I bumped up the version number.
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files (x86)\Microsoft SDKs\Expression\Blend\.NETFramework\v4.0\Libraries\System.Windows.Interactivity.dll</HintPath>
<Private>False</Private>
</Reference>
Yes I know it says version 4.5.0.0. I tried combinations of that as well. unless I missed some combination that works different that what would be expected.
It's open source so all of the code for the project is available, can someone please help me out? I'm afraid I am out of ideas.
Maybe in the App.config file this version number?
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
I don't want to just go through all of the code and change every place it says version to 3.5 or 4.0 or 4.5. That didn't seem like a very good idea.
As usual, once I see it, I'll probably want to kick myself!
Restart your web server and try again. Additionally, you can change the settings on Visual Studio. In my case, I went to Tools > Options > Projects and Solutions > Web Projects and checked Use the 64 bit version of IIS Express for web sites and projects - This was on VS Pro 2015. Nothing else fixed it but this.
The exception that is thrown when the file image of a dynamic link library (DLL) or an executable program is invalid.
It is strange that in my case, my project properties was already showing up as 4.5.2 but my app.config was still showing the runtime version as 2.0. I right clicked on project > chose project properties > updated target framework to 4.5.1 first and then updated to 4.5.2. That made the trick and updated the app.config as below:
Before:
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
After:
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
I had a similar problem as well with a super simple console app but mine turned out to be because it was relying on some libraries which were set to x86 only, and it wouldn't work on AnyCPU.
The fix: change my console app to also only build on x86 configuration and it worked.
System.BadImageFormatException was unhandled
Message: An unhandled exception of type 'System.BadImageFormatException' occurred in Unknown Module.
Additional information: Could not load file or assembly 'My.Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Screenshot of Exception message
Also see: Troubleshooting BadImageFormatException
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With