1

I have a WPF App which references a .NET Standard 2.0 library which contains ViewModels and uses MvvmLight. I've created an error handler which listens for messages from the ViewModels using GalaSoft.MvvmLight.Messaging.Messenger.

In visual studio, the app runs fine, but when I publish the app using ClickOnce then attempt to install and run it, the following exception occurs:

FileNotFoundException

The exception is thrown from the following line:

Messenger.Default.Register<Error>(this, ErrorHandler.DisplayError);

I was able to recreate the failure in a mostly empty project. The following is a link to a github repo with the project, if you'd like to see for yourself: SystemRuntimeFail Demo

After 3 days searching through stackoverflow posts for information on how to fix this and trying just about everything, I'm very nearly at my wit's end. Please help!

Athari
  • 33,702
  • 16
  • 105
  • 146
Katie
  • 1,498
  • 1
  • 15
  • 33
  • Did you read this? https://stackoverflow.com/questions/42755274/visual-studio-2017-could-not-load-file-or-assembly-system-runtime-version-4 – mm8 Nov 01 '17 at 11:20
  • Yes I did, and unfortunately it wasn't helpful. I had already had a reference to NetStandard.Library in my main project (I've added it to the SystemRuntimeFail demo now as well). I also tried adding a binding redirect, but unfortunately I don't know what version I'm supposed to be redirecting to, and I'm not really sure how to figure that out either. – Katie Nov 01 '17 at 21:00

1 Answers1

1

I managed to fix the issue by adding binding redirects to app.config for each assembly that this happened with.

I was tripped up by this answer which included a <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> tag enclosing all of the <dependentAssembly>s. When I tried this, it didn't work. It wasn't until I tried removing that enclosing tag that I made progress. I added binding redirects for each assembly that I saw an exception raised for and it finally worked.

Below is my full app.config. The part that I needed to add in order to resolve this issue was everything within the <runtime> tags

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
  </startup>
  <runtime>
    <dependentAssembly>
      <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="System.ObjectModel" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="System.Collections" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="System.Reflection.Extensions" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="System.Threading" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="System.Linq" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
    </dependentAssembly>
  </runtime>
</configuration>

I pushed the change to this repository fixing the issue

Katie
  • 1,498
  • 1
  • 15
  • 33