【问题标题】:Desktop Bridge app with PushNotificationChannel cannot find file 'System.Runtime.WindowsRuntime'带有 PushNotificationChannel 的桌面桥应用程序找不到文件“System.Runtime.WindowsRuntime”
【发布时间】:2018-10-07 13:35:26
【问题描述】:

我正在尝试允许桌面桥应用程序注册来自 Azure 通知中心的 WNS 通知,但是当我实际使用 UWP API 时它会抛出

`System.IO.FileNotFoundException: '无法加载文件或程序集'System.Runtime.WindowsRuntime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' 或其依赖项之一。系统找不到指定的文件。'

内部例外

FileNotFoundException:无法加载文件或程序集“System.Runtime.WindowsRuntime,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”或其依赖项之一。系统找不到指定的文件。

我按照the Visual Studio packaging instructions 设置了我的解决方案。我的包项目具有 Fall Creators Update 的目标版本、周年更新的最低版本,并且我将它与 Windows 开发中心项目相关联以支持 WNS。我所有的 .NET Framework 项目都针对 v4.6.2。如果我不调用任何 UWP API,则打包的应用程序可以完美运行。

所有 WNS 代码都在一个类库项目中,并且该项目被我的桌面应用程序引用(它被添加到包项目的应用程序中)。类库引用了Microsoft's tutorial 中的所有六个文件,其中三个 .winmd 文件的 Copy Local = False:

  • 来自C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5 的三个 DLL
  • C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Facade\Windows.winmd
  • C:\Program Files (x86)\Windows Kits\10\References\10.0.16299.0\Windows.Foundation.UniversalApiContract\5.0.0.0\Windows.Foundation.UniversalApiContract.winmd
  • C:\Program Files (x86)\Windows Kits\10\References\10.0.16299.0\Windows.Foundation.FoundationContract\3.0.0.0\Windows.Foundation.FoundationContract.winmd

实际的推送通知功能在异步方法中:

public namespace WnsClassLibrary
{
    public class WnsChannelService
    {
        private PushNotificationChannel _channel;

        public async Task CreateChannel()
        {
            _channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
        }
    }
}

当桌面应用程序启动时,它会尝试调用 CreateChannel() 作为未等待的异步方法,然后抛出异常 - 据我所知,它甚至没有真正进入方法。

有谁知道为什么会发生这种情况或我如何解决它?我尝试按照UWP application: Could not load file or assembly 'System.Runtime.WindowsRuntime, Version=4.0.14.0 中的建议将打包项目的最低版本设置为 Fall Creators Update,但我仍然遇到同样的异常。

【问题讨论】:

  • 尝试从此处引用 windows.winmd:C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.16299.0\Windows.winmd。如果这没有帮助,你能分享一个重现吗?
  • 这有帮助吗?
  • @StefanWickMSFT 引用 Windows.winmd 仍然给出相同的异常(添加后我必须删除对 Windows.Foundation.UniversalApiContract 的引用,以防止 Visual Studio 出错,因为 PushNotificationChannel 已在两个库中定义)。我正在组建一个可以重现该问题的缩小项目。

标签: c# push-notification uwp desktop-bridge


【解决方案1】:

看起来问题实际上可能不在桌面桥或 UWP API 引用中,而只是错误配置的程序集绑定重定向。

在尝试让异常出现在较小的解决方案中时,我发现

<configuration>
  <!--[unrelated configuration data...]-->
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime.WindowsRuntime" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

在桌面应用程序和 WNS 类库的 app.config 文件中。删除 &lt;runtime&gt; 元素会使一切正常运行,并将其复制/粘贴到我的复制项目中会使 System.IO.FileNotFoundException 开始出现。

我无法弄清楚是什么添加了该程序集绑定重定向或使其再次发生,但桌面应用程序最初是 .Net 4.5,并且经过大量实验迁移到 .Net 4.6.2,更新所有 Nuget 包,并实现桌面桥。我最好的猜测是,在此过程中可能有什么东西触发了 Nuget 自动配置器?

【讨论】:

    猜你喜欢
    • 2019-10-19
    • 1970-01-01
    • 2013-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多