corrupted-state-exception

Gracefully handling corrupted state exceptions in .NET Core

℡╲_俬逩灬. 提交于 2019-12-22 13:49:10
问题 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

How to terminate .NET application on a specific exception - possibly without stack unwinding?

送分小仙女□ 提交于 2019-12-13 02:24:29
问题 I have a .NET application (service) that consists of C# and C++ code. "Crashes" (i.e. System.AccessViolationException and other Corrupted State Exceptions) in the C++ Code will be ("non-") handled correctly, they will directly lead to my AppDomain.CurrentDomain.UnhandledException handler (which logs) and then the application will terminate, writing a WER dump file if so configured (which it is). For this application, I have determined that System.NullReferenceException is always a bug,

Gracefully handling corrupted state exceptions in .NET Core

折月煮酒 提交于 2019-12-06 09:24:46
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"

Gracefully handling corrupted state exceptions

自作多情 提交于 2019-11-27 19:24:16
Related to this question , I would like to force CLR to let my .NET 4.5.2 app catch Corrupted State Exceptions, for the sole purpose of logging them and then terminating the application. What's the correct way to do this, if I have catch (Exception ex) at several places around the app? So, after I specify the <legacyCorruptedStateExceptionsPolicy> attribute, if I understood correctly, all the catch (Exception ex) handlers will catch exceptions like AccessViolationException and happily continue. Yeah, I know catch (Exception ex) is a Bad Idea™, but if CLR would at least put the correct stack

Gracefully handling corrupted state exceptions

元气小坏坏 提交于 2019-11-26 22:48:14
问题 Related to this question, I would like to force CLR to let my .NET 4.5.2 app catch Corrupted State Exceptions, for the sole purpose of logging them and then terminating the application. What's the correct way to do this, if I have catch (Exception ex) at several places around the app? So, after I specify the <legacyCorruptedStateExceptionsPolicy> attribute, if I understood correctly, all the catch (Exception ex) handlers will catch exceptions like AccessViolationException and happily continue