Per Lundberg

Random thoughts from a BizTalk developer
posts - 10, comments - 10, trackbacks - 0

My Links

News

Archives

Post Categories

Trouble getting TargetInvocationException on your ASP.NET web application?`

Sometimes, you get pretty unclear exception messages. The message below is one example of such:

    Exception type: TargetInvocationException
    Exception message: Exception has been thrown by the target of an invocation.

    [...some stuff removed...]

    Stack trace:    at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance)
   at System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments)
   at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
   at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
   at System.Web.UI.WebControls.ListView.PerformSelect()
   at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
   at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()
   at System.Web.UI.WebControls.ListView.CreateChildControls()
   at System.Web.UI.Control.EnsureChildControls()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
 
I mean, this doesn't tell you anything about where in your code the problem occured. Or does it?

Well, actually, it doesn't. But by experience, you can learn that when working on stuff in an ASP.NET context, this usually (in my experience) means that the problem was caused by an ObjectDataSource. It might happen with other controls as well, but this is one case where I have seen it.

The ObjectDataSource "invokes" the method on the class you are telling it to get the data from (or perform the update, etc). The problem with this is that the "real" exception is not shown. My guess is that it would be in the "inner" exception in IIS, and this is not shown here, in the event viewer.

Anyway, when debugging the project inside Visual Studio, I still didn't get any exception information (maybe since I have a custom error handler page set up, that could be removed but it turned out not to be necessary). But, what I did get was this:

'WebDev.WebServer.EXE' (Managed): Loaded 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\ff657321\e4c5c948\App_Web_vtrilm_y.dll', Symbols loaded.
'WebDev.WebServer.EXE' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Diagnostics.ServiceModelSink\3.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Diagnostics.ServiceModelSink.dll'
A first chance exception of type 'System.IndexOutOfRangeException' occurred in System.Data.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpUnhandledException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpUnhandledException' occurred in System.Web.dll
The thread 0x2bb4 has exited with code 0 (0x0).

The red line at least gives you the name of the exception, which in this case was enough to lead me to the real cause of the problem.

Anyway, that's all for now!

Print | posted on Thursday, March 19, 2009 1:26 PM | Filed Under [ ASP.NET C# ]

Feedback

Gravatar

# re: Trouble getting TargetInvocationException on your ASP.NET web application?`

I am also getting the similar error.TargetInvocationExceptionthrown.
at "return (IPetShopCacheDependency)Assembly.Load(path).CreateInstance(fullyQualifiedClass);" for my class DependencyAccess.cs of the MS Petshop4 application.

I tried referring http://support.microsoft.com/kb/828991 and set the gacutil for the PetShopCacheDependency.dll and it was succesfully created in its directory.I tried executing it again but still it thrws error.Please suggest and rectify me if I am doing wrong steps!
9/16/2009 2:58 PM | sadz
Gravatar

# re: Trouble getting TargetInvocationException on your ASP.NET web application?`

Don't know exactly what could be causing this, but try these hints (if it still hasn't been solved):

- Split the line above into multiple lines:
var assembly = Assembly.Load(path);
var instance = assembly.CreateInstance(fullyQualifiedClass);
return instance;
- Then, run this in the Visual Studio debugger. Look into the variables and make sure the path looks decent, likewise with the fully qualified class name.

Well, maybe this could help to get you going.
9/21/2009 12:15 AM | Per Lundberg
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: