Exception is rethrown when invoking a WCF service?

J

james

I have a console app with the code:

public static void Main(String[] args)
{
AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(
delegate(object sender, UnhandledExceptionEventArgs e)
{
using (ErrorReportProxy proxy = new ErrorReportProxy())
{
proxy.Log(e.ExceptionObject as Exception);
}

Environment.Exit(-1);
});

throw new Exception("Kaboom!");
}

public class ErrorReportProxy : ClientBase<IErrorReport>
{
public void Log(Exception e)
{
Channel.Log(e);
}
}

When stepping through the code I see the exception get thrown and my
delegate get invoked, but when Channel.Log is called in the proxy the
debugger jumps back to the the "Kaboom!" exception (is it rethrown?).
This puts the app in a loop ... If I run the app outside of VS.net it
freezes until Windows shuts it down. Any ideas? Really weird behavior
I thought I understood this platform until today :/

Also there is no problem if I do something like
new ErrorReportProxy().Log(new Exception("Works Fine"));

Thanks,
James
 
N

Nicholas Paldino [.NET/C# MVP]

James,

It seems like the WCF proxy is throwing an exception, and therefore
starting an infinite loop. There should be a different exception called
when you call Log.

You should also have a try section in your delegate which will catch
exceptions and handle them, lest you get into an infinite loop for unhandled
exceptions (like you are now).

Hope this helps.
 
J

james

Thanks Nicholas you are completely correct. Wrapping the proxy in a
try catch let me see the correct error ( a formatter exception of
somesuch ). It looks like VS acts a little wacky when dealing with
more than one unhandled exception (why it kept telling me KABOOM
instead of the latest exception).

-James

James,

It seems like the WCF proxy is throwing an exception, and therefore
starting an infinite loop. There should be a different exception called
when you call Log.

You should also have a try section in your delegate which will catch
exceptions and handle them, lest you get into an infinite loop for unhandled
exceptions (like you are now).

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


I have a console app with the code:
public static void Main(String[] args)
{
AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(
delegate(object sender, UnhandledExceptionEventArgs e)
{
using (ErrorReportProxy proxy = new ErrorReportProxy())
{
proxy.Log(e.ExceptionObject as Exception);
}
Environment.Exit(-1);
});

throw new Exception("Kaboom!");
}
public class ErrorReportProxy : ClientBase<IErrorReport>
{
public void Log(Exception e)
{
Channel.Log(e);
}
}
When stepping through the code I see the exception get thrown and my
delegate get invoked, but when Channel.Log is called in the proxy the
debugger jumps back to the the "Kaboom!" exception (is it rethrown?).
This puts the app in a loop ... If I run the app outside of VS.net it
freezes until Windows shuts it down. Any ideas? Really weird behavior
I thought I understood this platform until today :/
Also there is no problem if I do something like
new ErrorReportProxy().Log(new Exception("Works Fine"));
Thanks,
James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top