使用 StoreContext 时 Release 模式下的 .NET Native 序列化异常

.NET Native serialization exception in Release mode when using StoreContext

我想在我的 UWP 应用程序中管理一些加载项。应用程序针对 minimum/target Windows 10 Fall Creators Update(均为 16299 SDK)。

我有一个名为 LicenseHelper 的 class,它使用 Windows.Services.Store 命名空间下的 StoreContext class。一切都在调试模式下构建良好。但是,如果我想在 x64 和 x86 架构的发布模式下构建,编译器会抛出以下序列化错误:

Generating serialization code
2>  Compiling interop code
2>C:\Users\Burak\.nuget\packages\microsoft.net.native.compiler.1.8\tools\Microsoft.NetNative.targets(788,5): error : Error generating serialization code for the root type SimpleStream.Helpers.LicenseHelper: Cannot find the assembly 'Windows.Services.Store.StoreContract' in the probing directories.
2>  Generating System.Reflection.DispatchProxy proxy code.
2>C:\Users\Burak\.nuget\packages\microsoft.net.native.compiler.1.8\tools\Microsoft.NetNative.targets(788,5): error : ILT0032: Failed to compile serialization code. See the build log for error details.

如果我删除与 StoreContext 相关的所有内容,构建就没问题了。在任何地方都没有直接使用 StoreContract 结构。只需一个简单的 StoreContext 定义就足以让编译器在 Release 版本上使序列化失败。

另一件事是,我曾经让它工作过。第一个使用 StoreContext 的包已经在商店中,具有相同的设置,如 min/target SDK 版本和 .NET Core UWP 包 (6.1.9)。不知道为什么它不再工作了。

尝试升级 .NET Core nuget 以预览并稍微降级它们甚至没有帮助。

这可能是编译器甚至 sdk 本身的内部错误,但我不知道。

这背后的原因可能是什么?

在这种情况下,我认为这是一个兼容性问题,Prism 不完全支持最新的 Windows 版本。

StoreContext 文档对此提供了一些指示。

https://docs.microsoft.com/en-us/uwp/api/Windows.Services.Store.StoreContext