Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have an webapi application running .net4 that I am trying to get working on a server. The api works fine locally.

Could not 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 get this to work on my server?

like image 227
Diver Dan Avatar asked Jan 16 '23 11:01

Diver Dan


2 Answers

Are you sure you were compiling against .NET 4 and not .NET 4.5? We moved ExtensionAttribute to mscorlib in .NET 4.5 (so we could put extension methods in mscorlib). I'd expect to see an error like that if you compiled something against .NET 4.5 and tried to run it on .NET 4.

EDIT: Actually, if you are using ILMerge, you need to use the path to the .NET 4.0 reference assemblies in the targetplatform switch, instead of the path to the implementation, 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

like image 109
Daniel Plaisted Avatar answered Feb 14 '23 17:02

Daniel Plaisted


Another possible solution (others with same exception) could be that your build server has not have the .net 4.0 reference assemblies, after installing .net 4.5 you'll need to copy them from your dev box.

These are typically somewhere like:

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

For more details see Marc's blog post

like image 21
Myster Avatar answered Feb 14 '23 16:02

Myster