我基本上有一个重复的问题,但对于 .NET Core。
我有核心控制台应用程序:
class Program
{
static void DoSomeAccessViolation()
{
// if you have any questions about why this throws,
// the answer is "42", of course
var ptr = new IntPtr(42);
Marshal.StructureToPtr(42, ptr, true);
}
[SecurityCritical]
[HandleProcessCorruptedStateExceptions]
static void Main(string[] args)
{
try
{
DoSomeAccessViolation();
}
catch (Exception ex)
{
Console.Error.WriteLine(ex);
}
}
}
我试图添加一个 Settings.setting 文件
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="ConsoleApp2" GeneratedClassName="Settings1">
<Profiles />
<Settings>
<Setting Name="legacyCorruptedStateExceptionsPolicy" Type="System.Boolean" Scope="Application">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
我尝试根据文档设置环境变量:
C:\>set COMPlus_legacyCorruptedStateExceptionsPolicy=1
C:\>dotnet run
或者
C:\>set COMPlus_legacyCorruptedStateExceptionsPolicy=true
C:\>dotnet run
(在 Windows 上)。但是没有任何效果,应用程序总是在不打印异常的情况下严重崩溃。