双异常不一致(System.IO.FileNotFoundException / System.Runtime 汇编版本)
double exception inconsistency (System.IO.FileNotFoundException / System.Runtime assembly Version)
在 WPF 应用程序中,我正在创建一个 Prism.Unity.UnityBootstraper
子类,在此上下文中为 Bootstrapper:
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var bootstapper = new Bootstrapper();
bootstapper.Run();
}
构建很好,但是在执行时我有一个双重异常:
System.IO.FileNotFoundException: 'Could not load file or assembly
'System.Runtime, Version=4.1.1.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The
system cannot find the file specified.'
我有以下内部异常,其中版本不同:
FileNotFoundException: Could not load file or assembly
'System.Runtime, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The
system cannot find the file specified.
我重新安装了 nuget 包,并尝试仅使用这段代码创建一个独立的用例,但我无法重现异常。
发生了什么事,我该如何解决这个问题?
为了进一步调查,我激活了 FusionLog:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion]
"ForceLog"=dword:00000001
"LogFailures"=dword:00000001
"LogResourceBinds"=dword:00000001
"LogPath"="C:\Logs\Fusion\"
但是实用性fuslogvs.exe
不太实用;所以我选择了 powershell:
select-string "operation failed" *htm -ca | % {"$($_.filename):$($_.line)"}
来自我程序集的日志目录,在 c:/logs/fusion
中。我发现了 3 个问题,特别是:
System.Runtime, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a.HTM:The operation failed.
在文件中,我得到:
LOG: AppName = ShutterModeler.exe
Calling assembly : Prism, Version=6.3.0.0, Culture=neutral, PublicKeyToken=40ee6c3a2184dc59.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\soleil\Documents\Visual Studio 2017\Projects\ShutterModeler\x64\Debug\ShutterModeler.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 4.1.1.0.
LOG: Post-policy reference: System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Users/soleil/Documents/Visual Studio 2017/Projects/ShutterModeler/x64/Debug/System.Runtime.DLL.
LOG: Attempting download of new URL file:///C:/Users/soleil/Documents/Visual Studio 2017/Projects/ShutterModeler/x64/Debug/System.Runtime/System.Runtime.DLL.
LOG: Attempting download of new URL file:///C:/Users/soleil/Documents/Visual Studio 2017/Projects/ShutterModeler/x64/Debug/System.Runtime.EXE.
LOG: Attempting download of new URL file:///C:/Users/soleil/Documents/Visual Studio 2017/Projects/ShutterModeler/x64/Debug/System.Runtime/System.Runtime.EXE.
LOG: All probing URLs attempted and failed.
事实上,构建目标目录中没有 System.Runtime.DLL
文件。
但是,System.Runtime
已安装 (v4.3),并出现在 $(SolutionDir)\packages
中。在里面我找不到 dotnet 4.7.2 目标:
Name
----
MonoAndroid10
MonoTouch10
net45
net462
portable-net45+win8+wp80+wpa81
win8
wp80
wpa81
xamarinios10
xamarinmac20
xamarintvos10
xamarinwatchos10
我的 WPF 项目以 .net 4.7.2 为目标。
正如 Alex Ghiondea - MSFT 所建议的那样
我删除了:
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
来自 app.config
,不再需要 post-build 手动副本作为解决方法:
xcopy /y "$(SolutionDir)packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll" "$(TargetDir)"
您的应用程序 app.config 中似乎有 System.Runtime 的程序集绑定重定向。请删除它,我希望这个错误会消失
在 WPF 应用程序中,我正在创建一个 Prism.Unity.UnityBootstraper
子类,在此上下文中为 Bootstrapper:
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var bootstapper = new Bootstrapper();
bootstapper.Run();
}
构建很好,但是在执行时我有一个双重异常:
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'
我有以下内部异常,其中版本不同:
FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
我重新安装了 nuget 包,并尝试仅使用这段代码创建一个独立的用例,但我无法重现异常。
发生了什么事,我该如何解决这个问题?
为了进一步调查,我激活了 FusionLog:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion]
"ForceLog"=dword:00000001
"LogFailures"=dword:00000001
"LogResourceBinds"=dword:00000001
"LogPath"="C:\Logs\Fusion\"
但是实用性fuslogvs.exe
不太实用;所以我选择了 powershell:
select-string "operation failed" *htm -ca | % {"$($_.filename):$($_.line)"}
来自我程序集的日志目录,在 c:/logs/fusion
中。我发现了 3 个问题,特别是:
System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.HTM:The operation failed.
在文件中,我得到:
LOG: AppName = ShutterModeler.exe
Calling assembly : Prism, Version=6.3.0.0, Culture=neutral, PublicKeyToken=40ee6c3a2184dc59.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\soleil\Documents\Visual Studio 2017\Projects\ShutterModeler\x64\Debug\ShutterModeler.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 4.1.1.0.
LOG: Post-policy reference: System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Users/soleil/Documents/Visual Studio 2017/Projects/ShutterModeler/x64/Debug/System.Runtime.DLL.
LOG: Attempting download of new URL file:///C:/Users/soleil/Documents/Visual Studio 2017/Projects/ShutterModeler/x64/Debug/System.Runtime/System.Runtime.DLL.
LOG: Attempting download of new URL file:///C:/Users/soleil/Documents/Visual Studio 2017/Projects/ShutterModeler/x64/Debug/System.Runtime.EXE.
LOG: Attempting download of new URL file:///C:/Users/soleil/Documents/Visual Studio 2017/Projects/ShutterModeler/x64/Debug/System.Runtime/System.Runtime.EXE.
LOG: All probing URLs attempted and failed.
事实上,构建目标目录中没有 System.Runtime.DLL
文件。
但是,System.Runtime
已安装 (v4.3),并出现在 $(SolutionDir)\packages
中。在里面我找不到 dotnet 4.7.2 目标:
Name
----
MonoAndroid10
MonoTouch10
net45
net462
portable-net45+win8+wp80+wpa81
win8
wp80
wpa81
xamarinios10
xamarinmac20
xamarintvos10
xamarinwatchos10
我的 WPF 项目以 .net 4.7.2 为目标。
正如 Alex Ghiondea - MSFT 所建议的那样
我删除了:
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
来自 app.config
,不再需要 post-build 手动副本作为解决方法:
xcopy /y "$(SolutionDir)packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll" "$(TargetDir)"
您的应用程序 app.config 中似乎有 System.Runtime 的程序集绑定重定向。请删除它,我希望这个错误会消失