C# 从Asp.Net 4.7项目中引用.Net标准2.0库时出错

C# 从Asp.Net 4.7项目中引用.Net标准2.0库时出错,c#,asp.net,asp.net-web-api,.net-standard,.net-standard-2.0,C#,Asp.net,Asp.net Web Api,.net Standard,.net Standard 2.0,我有一个针对asp.NET4.7的MVC项目。 我还创建了一个面向.Net标准2.0的类库 如果我从MVC项目中引用类库,则在应用程序启动时会出现以下异常 System.MissingMethodException:'未找到方法: 未找到“消息”方法: 'System.Collections.ObjectModel.Collection'1 System.Web.Http.HttpConfiguration.get_MessageHandlers() 在 如果我删除引用,一切都会恢复正常。 有没

我有一个针对asp.NET4.7的MVC项目。 我还创建了一个面向.Net标准2.0的类库

如果我从MVC项目中引用类库,则在应用程序启动时会出现以下异常

System.MissingMethodException:'未找到方法:

未找到“消息”方法: 'System.Collections.ObjectModel.Collection'1 System.Web.Http.HttpConfiguration.get_MessageHandlers()

如果我删除引用,一切都会恢复正常。
有没有错误的想法?

如果您的mvc项目以.net 4.6.1为目标,您可以使用.net标准2.0类库。

您需要将此绑定重定向到web.config:

<dependentAssembly>
   <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
   <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
</dependentAssembly>

另外,请参阅所有组件中的Nuget软件包
<dependentAssembly>
   <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
   <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
</dependentAssembly>