15

I have downloaded published (code behind files are no there, combined with dll in bin folder) web application from Window Server 2008 where it is hosted, and open it with Visual Studio when I debug that application it shows following error:

"Could not load assembly because this assembly is built by a runtime newer than the currently loaded runtime"

I don't know how can I solve this problem and test application locally. Please help me.

Burgi
  • 421
  • 8
  • 24
Arun Rana
  • 8,426
  • 14
  • 67
  • 107

6 Answers6

19

This errors happens when the DotNet framework you are using is of older version than the one used to build the assembly. You need to check which version of framework is used to build those assemblies and then use the same or higher to debug too.

bishnu karki
  • 129
  • 1
  • 5
Sachin Shanbhag
  • 54,530
  • 11
  • 89
  • 103
  • so i am currently in V2008 so if i install .net framework 4 then can i run that application or i have to install vs2010?? – Arun Rana Mar 10 '11 at 04:54
  • @Arun - If you have dotNet 4 installed, that is enough. Do not need to install vs2010. Dont worry. – Sachin Shanbhag Mar 10 '11 at 06:17
  • This can happen for lots of other reasons too. – Russell Horwood Sep 22 '14 at 15:42
  • 1
    VS2017 (or whatever) - Expand the project's References leaf in the and look at each of the assembly's "Runtime Version" in the Properties dialog. One of them will have been built on an older .Net runtime target then your project's runtime target. – John Pittaway Aug 28 '19 at 20:03
6

I was getting this same error when running an installer for a Windows service, even when running the installer on the PC the installer was built on.

It turned out that although the Windows service project had been updated to .NET 4.5, the Setup project that was making the installer was still set to use .NET 2.0.

To check if the Setup project is using an older version of .NET than the project to be installed, in the Visual Studio Solution Explorer:

  1. Expand the Setup project;

  2. Under the Setup project, expand Detected Dependencies;

  3. Under Detected Dependencies select Microsoft .NET Framework and check the Version property. Select the appropriate .NET version from the dropdown list;

  4. Re-build the Setup project to create a new version of the installer.

Simon Elms
  • 17,832
  • 21
  • 87
  • 103
  • Had this problem too when installing a service. The detected dependency version of the .Net Framework was wrong for some reason and when I changed it the problem went away. Thanks a lot! – dbostream Nov 25 '15 at 09:35
  • @Simon Tewsi is correct, and it works for my case of Visual Studio 2013 and .net framework 4. I mistakenly selected option "Any". Thanks bro! – Dung May 13 '16 at 15:31
  • Thank you. P.S. You might need to double click Microsoft .NET Framework to open properties. – Augis Sep 21 '16 at 13:08
2

I just ran into this issue when the assembly was built with a target framework of .NET 4, and v4.0.30319 was installed on the server, and other 4.0 apps were running successfully.

The problem arose because the app had originally been built targeting 2.0, and new 4.0 assemblies were pushed, but not the app.config file, which we generally update separately.

This means the supportedRuntime attribute was not updated in the config and caused the error. Adding the following to the app.config fixed our issue:

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

Danny
  • 1,740
  • 3
  • 22
  • 32
  • In which section of web.config must I add this? – realtebo Feb 16 '18 at 09:22
  • 1
    In my case it was when I was running multiple apps on a server (not a web application), and I was upgrading one of them from 2.0 to 4.0, but I had forgotten to update the app.exe.config along with the binaries. So mine wasn't a web.config, but the `` tag is a child of the top-level `` element, which is also true for web.config also has, so I would just try it at that top level, right under `` – Danny Feb 16 '18 at 14:59
2

This error can have a lot of other reasons, too. I had the same problem, and nothing helped until I stumbled across this: TlbExp.exe error:This assembly is built by a runtime newer

Community
  • 1
  • 1
peregrin
  • 21
  • 1
0

Also check the application pool that this web site is running as. It could be framework 2.0 default on some older windows servers. Change it to framework 4.0.

Peter PitLock
  • 1,823
  • 7
  • 34
  • 71
0

One the the assemblies reference in the project might be built using a newer version of .net, check version of every assembly reference and correct accordingly.

Furqan Hameedi
  • 4,372
  • 3
  • 27
  • 34