0

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)"
Soleil
  • 6,404
  • 5
  • 41
  • 61
  • 1
    This kind of errors might be pretty hard to resolve as "one of its dependencies" is not informative enough. So the first step is to find out which exactly .dll fails to load. I would enable fusion log (https://stackoverflow.com/questions/255669/how-to-enable-assembly-bind-failure-logging-fusion-in-net) and tried to launch my application again. Then the logs might help you identify which .dll is actually causing the problem. – rs232 Jul 27 '18 at 09:23
  • 1
    It looks like you have an assembly binding redirect for System.Runtime in your application's app.config. Please remove that and I expect this error will go away. – Alex Ghiondea - MSFT Jul 30 '18 at 19:13
  • Thanks @AlexGhiondea-MSFT this indeed solved the issue. This should go as an answer so I can accept and close. Many thanks. – Soleil Jul 30 '18 at 22:13

1 Answers1

1

It looks like you have an assembly binding redirect for System.Runtime in your application's app.config. Please remove that and I expect this error will go away

Alex Ghiondea - MSFT
  • 3,182
  • 1
  • 8
  • 11