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!