Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.net c# exception handling fails in 64 bit mode

I am facing a problem in my c# webservice application. Exceptions are not handled at a certain point anymore. The application simply stops without any further messages/faults exceptions. This is what happens:

Problem:

  • in a catch section of a method, I throw a new Exception containing additional information on the exception;
  • the underlying exception comes from another part of my application; the 'stack' of exceptions is about 20, but this does not seem to be an issue here;
  • when using the VS2012 development server (which is 32 bit I assume), or IIS in 32 bit mode, the thrown exception is picked up by the calling method as expected (finally resulting in a FaultException of my webservice)

Steps I have taken so far or other information that might be useful:

  • I can easily reproduce the exception; it simply stops working at exactly the same point everytime I run my code. Unfortunately my project is too large/complicated to present it here though.
  • At first I assumed differences between the VS2012 development server on the one side and IIS on the other cause my problem. However, when I configure my application pool as 32 bit in IIS, everything works fine. Moving to 64 bit causes this behavior.
  • memory usage does not seem to be an issue; in my application I use (large) xml input files. Changes to (the size of) these files have no impact on my problem.
  • I tried using the diagnostic tools provided for webservices. These do not really help me, since I can see what happens (or should I say does not happen) while debugging my application in VS2012;

And here it comes! My original code looks like this:

try
{
  //some code here throws an exception
}
catch (Exception ex)
{
  throw new Exception("some message", ex); //after this line no activity anymore
}

When I change this to:

Exception myex = null;
try
{
  //some code here throws an exception
}
catch (Exception ex)
{
  myex = new Exception("some message", ex);
  return null;
}
finally
{
  if (myex!=null) throw myex;
}

my problem is solved!? Does anyone have an explanation for this behavior? I hope to rely on normal exception handling mechanisms.

Another remark: when I put a 'throw new Exception()' before the try{} section, my code runs fine as well (but of course, I do not want that).

Anyone any clue? Thanks in advance!

like image 957
Dirk Avatar asked Jun 19 '13 11:06

Dirk


1 Answers

Are you running this from a background worker? I think you could be running into an issue with thread locking up in your first section of code, but then the return null allows the thread to finish in your second section of code.

I have seen some errors along these same lines where using a MessageBox.Show() command will allow the code to work correctly.

like image 83
Ermac Pd Avatar answered Oct 27 '22 00:10

Ermac Pd