官方文档: Breaking change: CET supported by default - .NET Microsoft Learn
表现:
调用 OpenFileDialog 的 ShowDialog 将会异常崩溃,崩溃异常是 FAST_FAIL_SET_CONTEXT_DENIED
或退出错误码为 0xc0000409 STATUS_STACK_BUFFER_OVERRUN
修复的代码:
此问题已在 https://github.com/dotnet/runtime/pull/109074 修复
永久解决方法:
更新 dotnet sdk 版本,再次构建发布
理论分析更新 dotnet runtime 也有用,但我没有尝试过,欢迎大佬补充
临时解决方法:
如果不便更新 dotnet sdk 版本,可通过如下设置禁用 CET 开启
<CETCompat>false</CETCompat>
以上设置放在 csproj 项目文件的 PropertyGroup 里面,更改之后的 csproj 代码大概如下
<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFramework>net9.0</TargetFramework><ImplicitUsings>enable</ImplicitUsings><Nullable>enable</Nullable><CETCompat>false</CETCompat></PropertyGroup></Project>
相关问题:
- https://github.com/dotnet/wpf/issues/10305
- https://github.com/dotnet/wpf/issues/10318