"Exception has been thrown by the target of an invocation" error (mscorlib)

asp.netExceptionMscorlib

asp.net Problem Overview


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?

asp.net Solutions


Solution 1 - asp.net

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!

Solution 2 - asp.net

This can happen when invoking a method that doesn't exist.

Solution 3 - asp.net

I know its kind of odd but I experienced this error for a c# application and finally I found out the problem is the Icon of the form! when I changed it everything just worked fine.

I should say that I had this error just in XP not in 7 or 8 .

Solution 4 - asp.net

' 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

Solution 5 - asp.net

This error occurs to me due to I have not set my Project as StartUp Project

When I set my current project to Set As Start-Up Project then it gone.

Solution 6 - asp.net

Encounter the same error when tried to connect to SQLServer2017 through Management Studio 2014

enter image description here

The reason was backward compatibility

So I just downloaded the Management Studio 2017 and tried to connect to SQLServer2017.

Problem Solve!!

Solution 7 - asp.net

I just had this issue from a namespace mismatch. My XAML file was getting ported over and it had a different namespace from that in the code behind file.

Solution 8 - asp.net

This is may have 2 reasons

1.I found the connection string error in my web.config file i had changed the connection string and its working.

  1. Connection string is proper then check with the control panel>services> SQL Server Browser > start or not

Solution 9 - asp.net

Got same error, solved changing target platform from "Mixed Platforms" to "Any CPU"

Solution 10 - asp.net

In my case, this happened due to choosing the option to publish as a single file in VS (.NET 5 console app), once I changed it to publish normally the exception was gone.

Solution 11 - asp.net

I got this error after I tried to add a new controller in the Controller folder but the connection string was placed inside the entityFramework tag in Web.config file.

Solution 12 - asp.net

For me, it happens when there is an internal call to another server and that server is not answering in a logical time or the configuration to call it is wrong. I fixed the problem of connecting to another server, then I received the correct data from that server and the function that was responsible for calling that server is working properly then I do not receive that error.

Solution 13 - asp.net

I edited the validation field, the error was resolved.

builder.Property(x => x.Name)**.UseIdentityColumn()**.HasMaxLength(200);  
builder.Property(x => x.Name)**.IsRequired()**.HasMaxLength(200);

Solution 14 - asp.net

my problem was that i didnt put the connection string in the right place in the appsettings.json it was inside IIS Express object then i moved it inside profiles object it didnt work as well the i fixed the problem by putting it inside the appsettings.json { here }

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDonnie ThomasView Question on Stackoverflow
Solution 1 - asp.netGreg DView Answer on Stackoverflow
Solution 2 - asp.netCasey BurnsView Answer on Stackoverflow
Solution 3 - asp.netmohammad sepehriView Answer on Stackoverflow
Solution 4 - asp.netabcView Answer on Stackoverflow
Solution 5 - asp.netshaishav shuklaView Answer on Stackoverflow
Solution 6 - asp.netKmsView Answer on Stackoverflow
Solution 7 - asp.netGreg SipesView Answer on Stackoverflow
Solution 8 - asp.netSameer BahadView Answer on Stackoverflow
Solution 9 - asp.netJaime VasquezView Answer on Stackoverflow
Solution 10 - asp.netMeshalView Answer on Stackoverflow
Solution 11 - asp.netCSharp4etoView Answer on Stackoverflow
Solution 12 - asp.netBeny SadView Answer on Stackoverflow
Solution 13 - asp.netGörkemView Answer on Stackoverflow
Solution 14 - asp.netelad baruchView Answer on Stackoverflow