.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?
LVL 19
Steve EndowMicrosoft MVP - Dynamics GPAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve EndowMicrosoft MVP - Dynamics GPAuthor Commented:
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
0
Steve EndowMicrosoft MVP - Dynamics GPAuthor Commented:
After pondering the .NET 2 activity and doing some searching on the issue, I found the cause of the problem.

The .NET version is set in the exe.config file--something I completely forgot about.

When I deployed the new version of the console app, I only copied the new EXE and DLL files--I did not replace or update the exe.config file, so it still had the .NET 2.0 reference in it:

<startup><supportedRuntime version="v2.0.50727"/></startup><applicationSettings>

I modified the config file to read:

<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/></startup><applicationSettings>

After that change, the app worked fine.

Facepalm.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.