I have basically a duplicate question but for .NET Core.
I have Core console app:
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);
}
}
}
I've tried to add a Settings.setting file
<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>
and I've tried to set an environment variable according to docs:
C:\>set COMPlus_legacyCorruptedStateExceptionsPolicy=1
C:\>dotnet run
or
C:\>set COMPlus_legacyCorruptedStateExceptionsPolicy=true
C:\>dotnet run
(on Windows). But nothing works, the app always crashes hard without printing the exception.