10

Site runs fine locally, but throws this from Windows Azure Websites hosting environment.

CS0012: The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

So this is an infamous message and has a known fix;

<compilation ... >
  <assemblies>
    <add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </assemblies>
</compilation>

I understand that the ASP.NET pages/views are compiled at a different time to the controllers and other logic, (that vNext is finally going to address this), and that the above is adding a reference for the page compilation side of things.

But my question is: why does this work on my development machine but needs this extra config on the WAWS environment, which you'd think was perfectly setup?

I would like to know what's different, what's missing on the target environment such that referencing a portable library (portable, meaning it should 'just work' in a variety of environments) actually breaks stuff.

Moreover, why is it that when I reference a PCL, System.Object suddenly isn't found in Mscorlib. Once upon a time I used to understand all this, and then it all got confusing.

svick
  • 236,525
  • 50
  • 385
  • 514
Luke Puplett
  • 42,091
  • 47
  • 181
  • 266
  • have you added `using` to the top of the .cs class for the particular assembly / reference.. – MethodMan Dec 05 '14 at 19:24
  • 5
    @DJKRAZE: This error has nothing to do with namespaces. – SLaks Dec 05 '14 at 19:25
  • what version is the actual project built in 4.5 ..? also google the exact error for some additional links to others that have had the same error http://www.lyalin.com/2014/04/25/the-type-system-object-is-defined-in-an-assembly-that-is-not-reference-mvc-pcl-issue/ – MethodMan Dec 05 '14 at 19:27
  • 1
    You say your local machine doesn't require this fix, I assume you're referring to web.config. But if you look in your [machine.config](http://stackoverflow.com/questions/2325473/where-is-machine-config), does it have this configuration in there? – mason Dec 05 '14 at 19:39
  • @mason It was a good idea, but nope. It's not in there. Locally, `System.Runtime` in is the GAC, which I guess is why its not a problem locally. But what put it there? – Luke Puplett Dec 06 '14 at 10:13
  • Check the framework version of the "web app" that's configured in the portal? – andryuha Jun 18 '15 at 15:03

1 Answers1

0

PCL references system.runtime.dll, not mscorlib.dll and when asp.net compiles your view page, it doesn't add reference to system.runtime.dll. In your case, the C# compiler throws the error. But not sure why the issue only happens on WAWS environment.

mattfei
  • 498
  • 3
  • 5