In a WPF application, I'm creating a Prism.Unity.UnityBootstraper
subclass, Bootstrapper in this context:
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var bootstapper = new Bootstrapper();
bootstapper.Run();
}
Build is fine but, at exceution I have a double exception:
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.'
and I have together the following inner exception, where there the version is different:
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.
I did a reinstall of nuget packages, and tried to make an isolated use case with only this code, and I couldn't reproduce the exception.
What is happening and how can I resolve this hell ?
In order to investigate further I activated 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\\"
But the utility fuslogvs.exe
is rather not practical; so I went with powershell:
select-string "operation failed" *htm -ca | % {"$($_.filename):$($_.line)"}
from the log directory of my assembly, in c:/logs/fusion
. I spotted 3 problems, and in particular:
System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.HTM:The operation failed.
In the file, I got:
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.
And indeed, there was no System.Runtime.DLL
file in the directory build target.
However, System.Runtime
was installed (v4.3), and present in $(SolutionDir)\packages
. Inside I couldn't find the dotnet 4.7.2 target:
Name
----
MonoAndroid10
MonoTouch10
net45
net462
portable-net45+win8+wp80+wpa81
win8
wp80
wpa81
xamarinios10
xamarinmac20
xamarintvos10
xamarinwatchos10
My WPF project is targetting .net 4.7.2.
As suggested by Alex Ghiondea - MSFT
I removed:
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
from app.config
, and didn't need the post-build manual copy anymore as workaround:
xcopy /y "$(SolutionDir)packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll" "$(TargetDir)"