问题描述
我的 UWP 应用在发布模式下启动后直接崩溃,事件日志中出现以下错误:
错误的应用程序名称:MyApp.exe,版本:1.0.0.0,时间戳:0x6037ab09 错误模块名称:Windows.UI.Xaml.dll,版本:10.0.17763.1790,时间戳:0x05b3601b 异常代码:0xc000027b
当我安装调试版本时,一切正常。
解决方法
我在 5.00 版中使用 Microsoft.Extensions.Logging 和 Microsoft.Extensions.Options。事实证明,本地编译器会剥离一些运行时需要的部分。
我在这个 github 问题中找到了描述和解决方案:https://github.com/dotnet/runtime/issues/44697
所以我必须将所有程序集添加到位于 Properties 下的 Default.rd.xml:
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Application>
<Assembly Name="*Application*" Dynamic="Required All" />
<!-- Add your application specific runtime directives here. -->
<Assembly Dynamic="Required All" Name="Microsoft.Extensions.Options"/>
<Assembly Dynamic="Required All" Name="Microsoft.Extensions.Logging"/>
<Assembly Dynamic="Required All" Name="Microsoft.Extensions.Logging.Abstractions"/>
<Assembly Dynamic="Required All" Name="Microsoft.Extensions.Hosting"/>
</Application>
</Directives>