【问题标题】:Could not load file or assembly 'System.Runtime' in deployed WPF ClickOnce App referencing MvvmLight from .Net Standard Library无法在已部署的 WPF ClickOnce 应用程序中加载文件或程序集“System.Runtime”,该应用程序引用来自 .Net 标准库的 MvvmLight
【发布时间】:2018-01-10 22:20:59
【问题描述】:

我有一个 WPF 应用程序,它引用了一个包含 ViewModel 并使用 MvvmLight 的 .NET Standard 2.0 库。我创建了一个错误处理程序,它使用GalaSoft.MvvmLight.Messaging.Messenger 侦听来自 ViewModel 的消息。

在 Visual Studio 中,应用运行良好,但是当我使用 ClickOnce 发布应用然后尝试安装并运行它时,出现以下异常:

从下面一行抛出异常:

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

我能够在一个几乎是空的项目中重现失败。以下是该项目的 github 存储库的链接,如果您想亲自查看: SystemRuntimeFail Demo

在通过 stackoverflow 帖子搜索有关如何解决此问题的信息并尝试几乎所有方法 3 天后,我几乎无计可施。请帮忙!

【问题讨论】:

  • 是的,我这样做了,不幸的是它没有帮助。我已经在我的主项目中引用了 NetStandard.Library(我现在也将它添加到 SystemRuntimeFail 演示中)。我也尝试添加绑定重定向,但不幸的是我不知道我应该重定向到哪个版本,我也不确定如何解决这个问题。

标签: .net wpf clickonce mvvm-light .net-standard


【解决方案1】:

我设法通过为发生这种情况的每个程序集向 app.config 添加绑定重定向来解决此问题。

我被this answer 绊倒了,其中包含一个包含所有&lt;dependentAssembly&gt;s 的&lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt; 标签。当我尝试这个时,它没有用。直到我尝试删除该封闭标签,我才取得了进展。我为每个我看到引发异常的程序集添加了绑定重定向,它终于起作用了。

以下是我的完整 app.config。为了解决这个问题,我需要添加的部分是 &lt;runtime&gt; 标签中的所有内容

<?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>

我将更改推送到 this repository 解决问题

【讨论】:

    猜你喜欢
    • 2013-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多