views:

9314

answers:

3

Hi,

I have a website developed in ASP.Net 2.0 that is throwing the error

"Exception has been thrown by the target of an invocation"

in the production environment. It was not throwing this error in development.

The source is 'mscorlib', and the stack trace says the error at

System.RuntimeMethodHandle._InvokeMethodFast.

The only thing I've changed since my last upload to production is that I've started using Membership controls (Login, LoginView), and have added a few more stored procedures and tables, etc. The membership depends upon a custom provider I've written.

Anybody have a clue why this could be happening?

+4  A: 

I'd suggest checking for an inner exception. If there isn't one, check your logs for the exception that occurred immediately prior to this one.

This isn't a web-specific exception, I've also encountered it in desktop-app development. In short, what's happening is that the thread receiving this exception is running some asynchronous code (via Invoke(), e.g.) and that code that's being run asynchronously is exploding with an exception. This target invocation exception is the aftermath of that failure.

If you haven't already, place some sort of exception logging wrapper around the asynchronous callbacks that are being invoked when you trigger this error. Event handlers, for instance. That ought to help you track down the problem.

Good luck!

Greg D
Hi,Thanks for your response! I have, in fact, exception logging, which is reporting the error. The code also checks for an inner exception. Maybe I should check at multiple levels (previous error, further level of exceptions). Thanks for the suggestion!
Wild Thing
You were right! Looking into the full exception history showed me the true exception (Tableadapter has the development connection string)!
Wild Thing
A: 

' Get the your application's application domain. Dim currentDomain As AppDomain = AppDomain.CurrentDomain

' Define a handler for unhandled exceptions. AddHandler currentDomain.UnhandledException, AddressOf MYExHandler

' Define a handler for unhandled exceptions for threads behind forms. AddHandler Application.ThreadException, AddressOf MYThreadHandler

Private Sub MYExnHandler(ByVal sender As Object, _ ByVal e As UnhandledExceptionEventArgs) Dim EX As Exception EX = e.ExceptionObject Console.WriteLine(EX.StackTrace) End Sub

Private Sub MYThreadHandler(ByVal sender As Object, _ ByVal e As Threading.ThreadExceptionEventArgs) Console.WriteLine(e.Exception.StackTrace) End Sub

' This code will throw an exception and will be caught. Dim X as Integer = 5 X = X / 0 'throws exception will be caught by subs below

abc
+1  A: 

I got this. It was because I was Invoking a method that didn't exist. Typo... my bad.

Casey Burns
This was my problem in a Surface project. My control in the xaml file pointed to event handlers that didn't exist (actually the names didn't match up correctly).
Brian