运行ASP.NET Web应用程序时找不到System.Runtime 4.1.0.0 [英] Could not find System.Runtime 4.1.0.0 when running ASP.NET web application

查看:415
本文介绍了运行ASP.NET Web应用程序时找不到System.Runtime 4.1.0.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用以下项目创建了一个可移植类库。json

  {
supports: {},
依赖项:{
Microsoft.CSharp: 4.0.1,
Microsoft.NETCore.Portable.Compatibility: 1.0.1,
NETStandard.Library: 1.6.0,
System.Runtime.Serialization.Primitives: 4.1.1,
System.Runtime: 4.1.0
},
frameworks:{
net451:{},
netstandard1.5:{}
}
}

但是,当从ASP.NET应用程序(不是ASP.NET Core)引用它时,我得到以下运行时例外:

 无法加载文件或程序集'System.Runtime,版本= 4.1.0.0,区域性=中性,PublicKeyToken = b03f5f7f11d50a3a或其依赖项之一。该系统找不到指定的文件。 

如果我从控制台应用程序中引用它,则它运行不会出现问题。



有什么想法吗?



编辑



找到了一个解决方案在这里: https://stackoverflow.com/a/37639003/691045



对我来说,跨越csproj到xproj边界时,它似乎是Net Core Tools Preview的一个错误。为了证明这一点,如果有人通过nuget安装软件包:

  Install-Package System.Runtime 

System.Runtime project.json中看起来正确作为 System.Runtime: 4.1.0 。查看这些引用,可以看到该版本列为 System.Runtime(4.0.20)



只需将.net 4.6.2 dll从nuget缓存复制到bin中即可解决此问题。这样就可以直接引用,而无需打包PCL。



希望当我们达到Net Standard 2.0且工具成熟时,这种事情将成为过去。



更新::如果您使用最新的.Net Core版本(1.1)和二进制文件,则此问题已修复。工具预览仍在1.0.1上,因此您必须确保安装1.1的二进制文件。


I've created a Portable Class Library with the following projects.json

{
  "supports": {},
  "dependencies": {
    "Microsoft.CSharp": "4.0.1",
    "Microsoft.NETCore.Portable.Compatibility": "1.0.1",
    "NETStandard.Library": "1.6.0",
    "System.Runtime.Serialization.Primitives": "4.1.1",
    "System.Runtime": "4.1.0"
  },
  "frameworks": {
    "net451": {},
    "netstandard1.5": {}
  }
}

However, when referencing this from an ASP.NET application (not ASP.NET Core), I get the following runtime exception:

Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

If I reference it from a console application it runs without issues.

Any ideas?

Edit

Found a solution here: https://stackoverflow.com/a/37639003/691045

解决方案

As mentioned in the update one solution to this problem is to package up the PCL as a nuget package. This however goes contrary to what one is trying to do when one targets .Net Standard with a PCL. Also the package solution becomes cumbersome to debug.

To me it appears as a bug with Net Core Tools Preview when crossing the csproj to xproj boundary. To evidence this if one install the package via nuget:

Install-Package System.Runtime

The System.Runtime looks correct in the project.json as "System.Runtime": "4.1.0". Looking at the references, one will see that the version is listed as System.Runtime (4.0.20). Also the actual bin has absolutely reference to the actual dll.

Simply copying the .Net 4.6.2 dll from the nuget cache into the bin solves the problem. This allows for direct references without packaging up your PCL.

Hopefully when we hit Net Standard 2.0 and the tooling matures a bit more this type of thing will be a thing of the past.

UPDATE: If you use the latest .Net Core release (1.1) and binaries this is fixed. The tool preview is still on 1.0.1 so you have to make sure you install the binaries for 1.1.

这篇关于运行ASP.NET Web应用程序时找不到System.Runtime 4.1.0.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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