MethodInfo.Invoke and TargetInvocationException
- From: Lasse Vågsæther Karlsen <lasse@xxxxxxxxxxx>
- Date: Thu, 28 Feb 2008 10:52:42 +0100
We have a base class that relies heavily on MethodInfo.Invoke.
Often, as such things happen, exceptions are thrown in the method that was invoked, and this pops up as a TargetInvocationException, at the place of the Invoke command.
I have tried wrapping my call to Invoke like this:
try
{
mi.Invoke(...);
}
catch (TargetInvocationException ex)
{
throw ex.InnerException;
}
However, this changes the stack trace. Is there a way for me to re-throw the inner exception so that Visual Studio pops up at the method being invoked with the exception that was thrown there, instead of always stopping in our base class?
I am working on replacing the calls to Invoke with delegates, but it's a lot of code so it's neither quick going nor bug-free so I was hoping there was a temporary fix for this while I rework the code.
--
Lasse Vågsæther Karlsen
mailto:lasse@xxxxxxxxxxx
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3
.
- Follow-Ups:
- Re: MethodInfo.Invoke and TargetInvocationException
- From: Paul E Collins
- Re: MethodInfo.Invoke and TargetInvocationException
- Prev by Date: Re: empty lines
- Next by Date: Re: startdate / enddate sum
- Previous by thread: startdate / enddate sum
- Next by thread: Re: MethodInfo.Invoke and TargetInvocationException
- Index(es):
Relevant Pages
|