类型 'Exception' 是在未在 ASP.NET 中引用的程序集中定义的 5 RC1
The type 'Exception' is defined in an assembly that is not referenced in ASP.NET 5 RC1
这个问题很容易重现,但我不确定修复方法。我在 Windows 10, Visual Studio 2015. 我安装了 ASP.NET 5.
的 RC1
重现:
新建项目 -> Class 库(包)
编辑 project.json,将 EnterpriseLibrary.TransientFaultHandling
添加到 net451
依赖项。
"frameworks": {
"net451": {
"dependencies": {
"EnterpriseLibrary.TransientFaultHandling": "6.0.1304"
}
},
"dotnet5.4": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Runtime": "4.0.21-beta-23516",
"System.Threading": "4.0.11-beta-23516"
}
}
}
使Class1
实现ITransientErrorDetectionStrategy
。
public class Class1 : ITransientErrorDetectionStrategy
{
public Class1()
{
}
public bool IsTransient(Exception ex)
{
throw new NotImplementedException();
}
}
构建并出现错误:.NET Framework 4.5.1 error CS0012: The type 'Exception' 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'.
我已经尝试将 "System.Runtime": ""
添加到 project.json
中的 net451
依赖项,但无法解决。如果我尝试添加引用,"System.Runtime" 不存在于程序集列表中。
我想我需要使用 Class Library (Package)
,因为我从 ASP.NET 5 Web API 项目中引用它。
短期内我可以在没有 dotnet5.4
支持的情况下生活,据我所知,TransientFaultHandling 库尚不支持它。
但是如何让它针对 .NET 进行编译4.x?
对于Class Library (Package) 项目类型,您应该清楚地将依赖项添加到 C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1\Facades\System.Runtime.dll
- 在解决方案资源管理器中导航到您的托管桌面应用程序项目。
- 右键单击“引用”节点并单击“添加引用”。
- 单击“浏览”选项卡。
- 点击浏览....
- 导航到系统。Runtime.dll 外观。您通常可以在类似于以下的路径中找到它:%ProgramFiles(x86)%\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\Facades\System.Runtime.dll
通过MSDN
对于具有 PCL 的 asp.net MVC 项目,存在类似的错误消息。尝试替换 web.config 部分以避免这种情况。
<compilation debug="true" targetFramework="4.5"/>
到
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
这个问题很容易重现,但我不确定修复方法。我在 Windows 10, Visual Studio 2015. 我安装了 ASP.NET 5.
的 RC1重现:
新建项目 -> Class 库(包)
编辑 project.json,将 EnterpriseLibrary.TransientFaultHandling
添加到 net451
依赖项。
"frameworks": {
"net451": {
"dependencies": {
"EnterpriseLibrary.TransientFaultHandling": "6.0.1304"
}
},
"dotnet5.4": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Runtime": "4.0.21-beta-23516",
"System.Threading": "4.0.11-beta-23516"
}
}
}
使Class1
实现ITransientErrorDetectionStrategy
。
public class Class1 : ITransientErrorDetectionStrategy
{
public Class1()
{
}
public bool IsTransient(Exception ex)
{
throw new NotImplementedException();
}
}
构建并出现错误:.NET Framework 4.5.1 error CS0012: The type 'Exception' 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'.
我已经尝试将 "System.Runtime": ""
添加到 project.json
中的 net451
依赖项,但无法解决。如果我尝试添加引用,"System.Runtime" 不存在于程序集列表中。
我想我需要使用 Class Library (Package)
,因为我从 ASP.NET 5 Web API 项目中引用它。
短期内我可以在没有 dotnet5.4
支持的情况下生活,据我所知,TransientFaultHandling 库尚不支持它。
但是如何让它针对 .NET 进行编译4.x?
对于Class Library (Package) 项目类型,您应该清楚地将依赖项添加到 C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1\Facades\System.Runtime.dll
- 在解决方案资源管理器中导航到您的托管桌面应用程序项目。
- 右键单击“引用”节点并单击“添加引用”。
- 单击“浏览”选项卡。
- 点击浏览....
- 导航到系统。Runtime.dll 外观。您通常可以在类似于以下的路径中找到它:%ProgramFiles(x86)%\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\Facades\System.Runtime.dll
通过MSDN
对于具有 PCL 的 asp.net MVC 项目,存在类似的错误消息。尝试替换 web.config 部分以避免这种情况。
<compilation debug="true" targetFramework="4.5"/>
到
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>