9
votes

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.

1
have you added using to the top of the .cs class for the particular assembly / reference..MethodMan
@DJKRAZE: This error has nothing to do with namespaces.SLaks
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 lyalin.com/2014/04/25/…MethodMan
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, does it have this configuration in there?mason
@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

1 Answers

0
votes

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.