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 FatalExecutionEngineError.
Any idea why?
Thank you. Exception e = new Exception();
FieldInfo stackTraceFieldInfo = typeof(Exception).GetField("_stackTrace", BindingFlags.Instance | BindingFlags.NonPublic);
stackTraceFieldInfo.SetValue(e, serviceExceptionData.StackTrace);
...
Console.WriteLine(e)
FatalExecutionEngineError 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.
7 1593 Plater 7,872
Recognized Expert Expert
You know you can just type cast any derrived exception type into its base Exception type? -
Exception e = (Exception)serviceExceptionData;
-
Console.WriteLine(e)
-
You know you can just type cast any derrived exception type into its base Exception type? -
Exception e = (Exception)serviceExceptionData;
-
Console.WriteLine(e)
-
Would be easy..., but serviceExceptionData is just the object holding the StackTrace string I need to inject in the new exception. In my case, ServiceExceptionData does not derivate from Exception.
Plater 7,872
Recognized Expert Expert
And the strack trace in that string does not match the stracktrace that would exist if you went "throw new Exception()" at the same time as that string was populated?
And the strack trace in that string does not match the stracktrace that would exist if you went "throw new Exception()" at the same time as that string was populated?
I don't think this is a matter of 'Matching' or not.
When I do "Exception e = new Exception()", the StackTrace value is null.
Then, I set it to a valid StackTrace string. For example, stackTraceFieldInfo.SetValue(e, Environment.StackTrace);
would produce the same problem.
Plater 7,872
Recognized Expert Expert
Hmm, I guess the stacktrace value doesn't get populated until you "throw" it.
I am not sure why you cannot just set the value, possibly due to the way a debugger would interpret it, since it would use the stack trace to decide debugging information?
Was there anything on the net about the error message you got?
...the way a debugger would interpret it, since it would use the stack trace to decide debugging information?
If I enclose the above code in a try-catch, and run it in non-debbuging mode, no exception is catched. The app simply crashes with the classical "SetExceptionStackTrace has encountered a problem and needs to close. We are sorry for the inconvenience. If you were in the middle of something ...."
Was there anything on the net about the error message you got?
I didn't find any relevant information. That's why I posted this as a question here.
But you remarks gave an idea: I will study what MSDN says about 'Diagnosing Errors with Managed Debugging Assistants'. If someone has already some experience with this kind of stuff, please don't hesitate to give me your comments!
Ok, I got it.
The backing field of Exception.StackTrace is not _stackTrace but _stackTraceString.
Thanks Plater for your support.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Fiona McBride |
last post by:
Hi all,
I have a really odd problem with some Visual Basic .NET 2003 code;
I have a program that creates a number of windows which contain
RichTextBox, Timers (disabled) and menus. The code...
|
by: Vitling |
last post by:
For no apparent reason, a NullReference exception is thrown in
system.dll
(System.Net.Sockets.OverlappedAsyncResult.CompletionPortCallback).
Since I only get a disassembly from Visual Studio, it...
|
by: craig |
last post by:
I am wondering if there are some best practices for determining a strategy
for using try/catch blocks within an application.
My current thoughts are:
1. The code the initiates any high-level...
|
by: Jan |
last post by:
Hi,
If I put a try catch block for Server.Transfer call. It will catch a
System.Threading.ThreadAbortException exception like this. However, it
transfer the page to the correct page. Why did...
|
by: doubts |
last post by:
Hi all,
I am trying to convert my bulk of code from VC++ 6.0 to VC++.Net.
when using std::string type variable, the application causes exception
at one instance and does not cause an exception at...
| |
by: laredotornado |
last post by:
Hi,
I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed
using Apache's apxs and the php library was installed to
/usr/local/php. However, when I set my "error_reporting"...
|
by: cyberdaemon |
last post by:
The error message is a follows:
ERROR MESSAGE:
FatalExecutionEngineError -
The runtime has encountered a fatal error. The address of the error was at 0x79fca0da, on thread 0xf70. The error code...
|
by: Andrus |
last post by:
..NET 2 Winforms application.
How to create new setting and set it default value in userSettings section
of app.config file or overwrite existing setting value ?
I found code below in this list...
|
by: BobRoyAce |
last post by:
I am using VB.NET and I have a variable that is defined as Nullable(Of
Single) as follows:
Dim fMyNullableSingle as Nullable(Of Single)
Then, I have another variable as follows:
Dim...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |