7

My .NET site is working fine on Localhost. But, on my Server. I get this error.

"Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'."

(Can't post screenshot, due to Stack Overflow policy)

It's something to do with asp:ScriptManager. I have used it before on the same server, but now, it's showing an error.

PS: When I remove Scriptmanager, the code runs fine.

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

johnnyRose
  • 7,310
  • 17
  • 40
  • 61
dan1
  • 435
  • 2
  • 6
  • 9

2 Answers2

18

This error comes about when you compile an application against .Net 4.5 but then run it on a machine that only has 4.0 installed.

In .Net 4.5 the ExtensionAttribute class was moved from System.Core to mscorlib. There is a type forwarder in System.Core that points to the new location in mscorlib. If you compile an app against 4.5 it will expect to find ExtensionAttribute in mscorlib. If you then run it against 4.0 you will get this exception because in actually lives in System.Core in 4.0

To fix this either deploy 4.5 to the server or make sure that you build against 4.0

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • Hi Jared, I rechecked. I have built my Website (It's not a Web App) with 4.0 Framework. I checked my page property , it says framework 4.0. What should I do now ? – dan1 Nov 12 '13 at 16:07
  • @DanyalOzair something in your dependency chain is still built against 4.5. You may need to break open the assemblies with reflector / ilspy and hand check. This is by far the most likely explanation for why you would get this message – JaredPar Nov 12 '13 at 16:13
  • Hi jared, I Am using NewtonSoft package for Json. VS 2012 Package installer installed that for me. Package Config says"__" . So, that is sorted. Unless, VS is bluffing. I am using another DLL, it's Twitterizer2.dll , this might be causing problem. But, Twitterizer2 Documentation says, they support ASP.net > 3.5 , How do I target 4.0 with Twitterizer. I am sorry , I am new to .Net framework. – dan1 Nov 13 '13 at 09:26
  • 1
    You were right, Twitterizer2.dll was targetting 4.5, I changed it. And it's working fine. – dan1 Nov 13 '13 at 14:23
-1

JUST install microsoft framework v4.5 or higher on you pc or server it's worked for me very well

Hisen
  • 13
  • 9