473,495 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Setting Exception._stackTrace value by reflexion causes a 'FatalExecutionEngineError'

5 New Member
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.
Aug 27 '08 #1
7 1593
Plater
7,872 Recognized Expert Expert
You know you can just type cast any derrived exception type into its base Exception type?
Expand|Select|Wrap|Line Numbers
  1. Exception e = (Exception)serviceExceptionData;
  2. Console.WriteLine(e)
  3.  
Aug 27 '08 #2
Arbiorix
5 New Member
You know you can just type cast any derrived exception type into its base Exception type?
Expand|Select|Wrap|Line Numbers
  1. Exception e = (Exception)serviceExceptionData;
  2. Console.WriteLine(e)
  3.  
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.
Aug 27 '08 #3
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?
Aug 27 '08 #4
Arbiorix
5 New Member
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.
Aug 27 '08 #5
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?
Aug 27 '08 #6
Arbiorix
5 New Member
...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!
Aug 28 '08 #7
Arbiorix
5 New Member
Ok, I got it.

The backing field of Exception.StackTrace is not _stackTrace but _stackTraceString.

Thanks Plater for your support.
Aug 28 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
277
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...
5
4013
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...
44
4155
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...
5
6749
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...
3
3194
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...
1
6435
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"...
2
2248
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...
8
16083
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...
2
3331
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...
0
6991
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...
0
7196
jinu1996
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...
0
7373
tracyyun
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...
0
5456
agi2029
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,...
0
3088
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...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1405
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 ...
1
649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
286
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.