WebAPI RC 'System.Runtime.CompilerServices.ExtensionAttribute' from the assembly 'mscorlib,

I have a webapi application working with .net4 that I am trying to get on the server. Api works fine locally.

Failed to load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089'.

What do I need to change to make this work on my server?

+4
source share
5 answers

Are you sure you are working with .NET 4, and not with .NET 4.5? We moved ExtensionAttribute to mscorlib in .NET 4.5 (so we can use extension methods in mscorlib). I expect to see such an error if you compiled something against .NET 4.5 and tried to run it on .NET 4.

EDIT: In fact, if you are using ILMerge, you need to use the path to .NET 4.0 link assemblies in the targetplatform switch instead of the implementation path, as described in this blog post: http://www.mattwrock.com/post/2012 /02/29/What-you-should-know-about-running-ILMerge-on-Net-45-Beta-assemblies-targeting-Net-40.aspx

+8
source

Another possible solution (others with the same exception) may be that your build server does not have a .net 4.0 link assembly after installing .net 4.5, you will need to copy them from your dev module.

Usually this is somewhere like:

C: \ Program Files (x86) \ Reference Assemblies \ Microsoft \ Framework.NETFramework \ v4.0

See Marc Blog Entry for more details.

+1
source

Also check out the DLLs your project depends on. I had the same problem and found that one problem was with the DLL. This DLL was an older version (compiled for .NET 4.0) on my local computer, where the site worked fine through localhost, but was a newer version (compiled for .NET 4.5) on a real server, where the site failed.

0
source

I had the same problem and fixed it by creating a new application pool for my site after installing the .NET Framework 4.5

0
source

I have little experience with .NET, and I had the same problem with System.Runtime.CompilerServices.ExtensionAttribute .

Solution: Remove the project links, the link to Framework 4.5, because in my case, since I did not install this Framework.

0
source

Source: https://habr.com/ru/post/948878/


All Articles