Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
644 views
in Technique[技术] by (71.8m points)

asp.net - The type 'System.Object' is defined in an assembly that is not referenced

I installed a Microsoft ASP.NET Web API Compression nuget package to my project and added a line to WebApiconfig inside Register method as shown in this link https://www.nuget.org/packages/Microsoft.AspNet.WebApi.MessageHandlers.Compression/

 GlobalConfiguration.Configuration.MessageHandlers.Insert(0, new CompressionHandler(new GZipCompressor(), new DeflateCompressor()));

Also added the following code to the web.config file

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

But I am getting an error

Error 1 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'. D:....App_StartWebApiConfig.cs

The compiler is complaining about GlobalConfiguration class with error above. I am using >NET Framework 4.5

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I got this same error and got around it by doing 2 things.

Background:

I'm building a simple test ASP.Net application to try to work with Google API's OAuth2.0. I used "nuget" to install the Google.Apis.Calendar.v3 (v1.13.1.509) library, and it brought in a lot of other dlls that it depends on.

The Error:

When compiling a seemingly simple ASP.Net project targeting "Framework 4.5" on Visual Studio 2015 for Web (Express). The error showed itself in 2 ways:

I originally compiled the code using the Build command Ctrl+F5. Then I got a build error, but without a entry in the "Error" tab that normally would point to a source code line. (The project just would stop building). The output was:

------ Build started: Project: oauth2.pylogen.com, Configuration: Debug Any CPU ------
Validating Web Site
Building directory '/App_Code/'.

E:Projectsoauth2.pylogen.comApp_CodeGoogle.Api.PylogenFlowMetadata.cs(26,13): error 
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'.
Validation Complete
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

I then proceeded by installing the dotNet Framework 4.6.1 Developer Pack (the newest version that is not a preview).

Then I restarted VS 2015 for Web and got build again. This time I got an entry in the "Error" tab, that pointed to a source line:

flowInit.Scopes = new string[] { Google.Apis.Calendar.v3.CalendarService.Scope.Calendar };

When I commented out this line, the project build. I could pretty much do nothing about this line, but I just wanted to show the obscurity of the error!

Solutions:

After installing Framework 4.6.1 Developer Pack. I also added this line to Web.Config:

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

After this my project build completely. My assumption would be that Google is referring to the older System.Runtime.dll (although their Nuget package detail is showing that the target framework is 4.5).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...