带有 PushNotificationChannel 的桌面桥应用找不到文件 'System.Runtime.WindowsRuntime'
Desktop Bridge app with PushNotificationChannel cannot find file 'System.Runtime.WindowsRuntime'
我正在尝试允许桌面桥应用程序注册来自 Azure 通知中心的 WNS 通知,但是当我实际使用 UWP API 时它抛出
`System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Runtime.WindowsRuntime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.'
内部例外
FileNotFoundException: Could not load file or assembly 'System.Runtime.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.
我按照 the Visual Studio packaging instructions 设置了我的解决方案。我的包项目有 Fall Creators Update 的目标版本,Anniversary Update 的最低版本,我将它与 Windows Dev Center 项目相关联以获得 WNS 支持。我所有的 .NET Framework 项目都以 v4.6.2 为目标。如果我不调用任何 UWP API,打包的应用程序运行完美。
所有 WNS 代码都在一个 Class 库项目中,该项目被我的桌面应用程序引用(添加到包项目的应用程序中)。 class 库具有对 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\UnionMetadata\Facade\Windows.winmd
C:\Program Files (x86)\Windows Kits\References.0.16299.0\Windows.Foundation.UniversalApiContract.0.0.0\Windows.Foundation.UniversalApiContract.winmd
C:\Program Files (x86)\Windows Kits\References.0.16299.0\Windows.Foundation.FoundationContract.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()
作为未等待的异步方法,这就是抛出异常的时候——据我所知,它甚至没有真正进入方法。
有谁知道为什么会发生这种情况或我如何解决它?我尝试按照 中的建议将打包项目的最低版本设置为 Fall Creators Update,但我仍然遇到相同的异常。
看起来问题实际上可能不在 Desktop Bridge 或 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 class 库的 app.config
文件中。删除 <runtime>
元素会使一切 运行 正常,并且 copy/pasting 它进入我的复制项目使 System.IO.FileNotFoundException 开始出现。
我不知道是什么添加了程序集绑定重定向或让它再次发生,但桌面应用程序最初是 .Net 4.5 并进行了大量实验以迁移到 .Net 4.6.2,更新所有 Nuget包,并实施桌面桥。我最好的猜测是,一路上可能有什么东西触发了 Nuget 自动配置器?
我正在尝试允许桌面桥应用程序注册来自 Azure 通知中心的 WNS 通知,但是当我实际使用 UWP API 时它抛出
`System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Runtime.WindowsRuntime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.'
内部例外
FileNotFoundException: Could not load file or assembly 'System.Runtime.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.
我按照 the Visual Studio packaging instructions 设置了我的解决方案。我的包项目有 Fall Creators Update 的目标版本,Anniversary Update 的最低版本,我将它与 Windows Dev Center 项目相关联以获得 WNS 支持。我所有的 .NET Framework 项目都以 v4.6.2 为目标。如果我不调用任何 UWP API,打包的应用程序运行完美。
所有 WNS 代码都在一个 Class 库项目中,该项目被我的桌面应用程序引用(添加到包项目的应用程序中)。 class 库具有对 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\UnionMetadata\Facade\Windows.winmd
C:\Program Files (x86)\Windows Kits\References.0.16299.0\Windows.Foundation.UniversalApiContract.0.0.0\Windows.Foundation.UniversalApiContract.winmd
C:\Program Files (x86)\Windows Kits\References.0.16299.0\Windows.Foundation.FoundationContract.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()
作为未等待的异步方法,这就是抛出异常的时候——据我所知,它甚至没有真正进入方法。
有谁知道为什么会发生这种情况或我如何解决它?我尝试按照
看起来问题实际上可能不在 Desktop Bridge 或 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 class 库的 app.config
文件中。删除 <runtime>
元素会使一切 运行 正常,并且 copy/pasting 它进入我的复制项目使 System.IO.FileNotFoundException 开始出现。
我不知道是什么添加了程序集绑定重定向或让它再次发生,但桌面应用程序最初是 .Net 4.5 并进行了大量实验以迁移到 .Net 4.6.2,更新所有 Nuget包,并实施桌面桥。我最好的猜测是,一路上可能有什么东西触发了 Nuget 自动配置器?