Link to home
Start Free TrialLog in
Avatar of Steve Endow
Steve EndowFlag for United States of America

asked on

.NET Error: Assembly is built by a runtime newer than the currently loaded runtime

I have upgraded a C# console app to .NET 4.5.1.  In the process, I removed all external library references and re-added new references to .NET 4.x versions of the DLLs.

The new 4.5.1 console app works properly on my development server, and I have tested it on 5 other machines, where it works fine as well.

However, when I deploy it to my client's workstation, it crashes immediately with this error:

Unhandled Exception:  System.BadImageFormatException: Could not load file or assembly 'myapp.exe' or one of its dependencies.  This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

I have checked that the client workstation has .NET 4.5.x installed (it shows version 4.5.2 in the registry (release 379893), and I've triple checked my DLL references.  My guess is that some DLL is different on the client machine.

As a test, I tried it on a second client workstation, and the same error occurred.  The second workstation was built by the same IT guy using the same files / installs, so we didn't get any new clues, but it tells me that the issue is not a random workstation-specific issue.

Rather than troubleshoot indirectly by guessing and trial and error, is there a tool to identify which DLL is causing this error?

Will Sysinternals Process Monitor or some other tool be able to identify the culprit?
Avatar of Steve Endow
Steve Endow
Flag of United States of America image

ASKER

I used Process Monitor on my development machine and on the client workstation to capture a trace of the EXE activity for comparison.

The only significant difference I'm seeing is that on the workstation, it appears to be loading / referencing .NET 2.0, whereas on my dev machine, it's clearly hitting .NET 4.

In the attached image, the activity on the left is my dev machine, on the client workstation is on the right.  On the left, there are numerous references to .NET 4, but on the right, it's mostly v2.0 with only a few brief references to .NET 4.

It seems that for some reason, the client workstation is thinking the app is .NET 2 instead of .NET 4.x.
NETVersionRefs.jpg
ASKER CERTIFIED SOLUTION
Avatar of Steve Endow
Steve Endow
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial