类型'System.Object的“在未被引用的程序集定义 [英] The type 'System.Object' is defined in an assembly that is not referenced

查看:8496
本文介绍了类型'System.Object的“在未被引用的程序集定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了微软的ASP.NET Web API的COM pression的NuGet包我的项目,并添加注册方法中一行WebApiconfig如在这个环节上的https://www.nuget.org/packages/Microsoft.AspNet.WebApi.MessageHandlers.Com$p$pssion/

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()));

还增加了以下code到web.config文件

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

错误1类型'System.Object的'在组装是没有定义
  引用。您必须添加一个引用程序集System.Runtime,
  版本= 4.0.0.0,文化=中立,
  公钥= b03f5f7f11d50a3a。 D:.... \\ App_Start \\ WebApiConfig.cs

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_Start\WebApiConfig.cs

编译器抱怨GlobalConfiguration类错误之上。 我使用> .NET框架4.5

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

推荐答案

我得到这个同样的错误,并通过做两件事情得到了解决它。

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

我建立一个简单的测试ASP.Net应用程序尝试与谷歌API的OAuth2.0的工作。我用的NuGet安装 Google.Apis.Calendar.v3(v1.13.1.509)库,它在很多其它的DLL,它依赖于带

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.

在编译一个看似简单的ASP.Net项目瞄准框架4.5上的Visual Studio 2015年的Web(前preSS)。错误表现出来了2种方式:

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:

我最初编译使用生成命令code Ctrl + F5键。后来我有一个生成错误,但没有在错误选项卡上,通常会指向一个源头code线项目。 (该项目只是将停止建设)。输出是:

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:\Projects\oauth2.pylogen.com\App_Code\Google.Api.Pylogen\FlowMetadata.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 ==========

然后我通过安装的dotNet 框架4.6.1开发包(中进行这不是一个preVIEW最新版本)。

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

然后我重新启动VS 2015 Web和得到再次建立。这一次,我在错误选项卡上的条目,即指着一个源代码行:

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 };

当我注释掉这一行,该项目构建。我可以pretty太多无能为力这一行,但我只是想显示错误的默默无闻!

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!

框架4.6.1开发包后。我还添加了此行到Web.config中:

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>

这是我的项目后建立完全。我的假设是,谷歌是指旧的System.Runtime.dll(虽然他们的NuGet包细节显示,目标框架是4.5)。

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).

这篇关于类型'System.Object的“在未被引用的程序集定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆