I need to set the value of the StackTrace property of an exception.
As this property has not setter, I do it by reflection on the private field _stackTrace.
When accessing the exception object, I get a FatalExecutionE ngineError.
Any idea why?
Thank you.
Exception e = new Exception();
FieldInfo stackTraceField Info = typeof(Exceptio n).GetField("_s tackTrace", BindingFlags.In stance | BindingFlags.No nPublic);
stackTraceField Info.SetValue(e , serviceExceptio nData.StackTrac e);
...
Console.WriteLi ne(e)
FatalExecutionE ngineError was detected
Message: The runtime has encountered a fatal error. The address of the error was at 0x79e7b217, on thread 0x14bc. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
As this property has not setter, I do it by reflection on the private field _stackTrace.
When accessing the exception object, I get a FatalExecutionE ngineError.
Any idea why?
Thank you.
Exception e = new Exception();
FieldInfo stackTraceField Info = typeof(Exceptio n).GetField("_s tackTrace", BindingFlags.In stance | BindingFlags.No nPublic);
stackTraceField Info.SetValue(e , serviceExceptio nData.StackTrac e);
...
Console.WriteLi ne(e)
FatalExecutionE ngineError was detected
Message: The runtime has encountered a fatal error. The address of the error was at 0x79e7b217, on thread 0x14bc. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
Comment