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

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

问题描述

我使用以下 projects.json 创建了一个可移植的类库

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": {}
  }
}

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

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.

有什么想法吗?

编辑

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

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

推荐答案

如更新中所述,解决此问题的一种方法是将 PCL 打包为 nuget 包.然而,这与当一个人使用 PCL 瞄准 .Net Standard 时试图做的事情背道而驰.此外,打包解决方案调试起来也很麻烦.

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.

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

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

System.Runtimeproject.json 中看起来正确,为 "System.Runtime": "4.1.0".查看参考资料,您会看到版本被列为System.Runtime (4.0.20).此外,实际的 bin 绝对引用了实际的 dll.

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.

只需将 .Net 4.6.2 dll 从 nuget 缓存复制到 bin 即可解决问题.这允许直接引用而无需打包您的 PCL.

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.

希望当我们达到 Net Standard 2.0 并且工具更加成熟时,这种类型的事情将成为过去.

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.

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

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天全站免登陆