Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded"

I'm getting the error: "This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded."

I have a .NET 4.0 dll project that is being called by a .NET 2.0 project. Is there a way to reconcile the difference in framework?

like image 616
Nick Myers Avatar asked May 15 '12 18:05

Nick Myers


2 Answers

I have a .NET 4.0 dll project that is being called by a .NET 2.0 project. Is there a way to reconcile the difference in framework?

Not that way round, no. The .NET 4 CLR can load .NET 2 assemblies (usually - there are a few exceptions for mixed-mode assemblies, IIRC), but not vice versa.

You'll either have to upgrade the .NET 2 project to .NET 4, or downgrade the .NET 4 project to .NET 3.5 (or earlier).

like image 56
Jon Skeet Avatar answered Sep 18 '22 21:09

Jon Skeet


If you have already tried all the other logical solutions on this page, then double check this. In my app.config I had a reference to an old framework.

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

should have been

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

The project tab correctly showed v4.0 but the app.config was not committed to our repo with that change. To fix it, I changed the framework to something else and back to 4.0 again, which updated my app.config file.

like image 33
user2209195 Avatar answered Sep 19 '22 21:09

user2209195