Partilhar via


Debugging a MissingMethodException, MissingFieldException, TypeLoadException

Say you've just installed some assemblies from a third party and now you're seeing a MissingMethodException, MissingFieldException, or TypeLoadException (during the run of an application using those assemblies). Below are the common causes.

Loading failures
First, check for assembly binding failures by getting the Fusion log. Look for the assembly containing that method/field/type or assemblies containing types referenced by it. If an assembly failed to load, use the instructions at the same link to help resolve that issue.

Unexpected assembly version loaded
But, if that's not the problem, turn on the Fusion log for everything - not just failures - and check to see if the wrong version of those assemblies is being loaded. Look at the display names requested. Are any requesting outdated versions, even after policy has been applied (see further down in the log for the post-policy display name)? If so, you may want to recompile part of your app so that it has current references.

Loaded from unexpected path
If that doesn't help, run filever.exe on the file at the path it was loaded from. You can get that from the loaded modules list in a debugger. It's also the last path listed in the Fusion log, for a successful log (if it's in the GAC, no path is listed). Make sure it is the same path as you would expect.

Not in this version of the assembly
Next, run ildasm.exe on the file at the path it was loaded from at runtime. Make sure that the method/field/type is there and is defined how you would expect it. Maybe the file has changed, adding or removing methods or the like, but the assembly version and location have stayed the same.

Invalid IL
Now, try running peverify.exe on the file containing the method/field/type using the path it was loaded from at runtime. If it gives an error, check back to see if there was a warning at compile-time for this file.

Comments

  • Anonymous
    May 31, 2004
    Suzanne, nice article on MissingMethodException , it helped me debug my problem , Many thanks

  • Anonymous
    June 23, 2005
    dir c:filever.exe /s shows nothing on my machine. I have VS.NET full install. Where do I get filever?

  • Anonymous
    November 28, 2005
    Hi Suzanne -

    You're debugging method looks like just what I need, except that I am getting my MissingMethodException on a PocketPC application I am developing. I am trying to open a connection to a PostgreSQL database on a PC to which the PocketPC is connected using Npgsql .NET drivers for PostgreSQL.

    I don't see any binding in my fusion log, because it's not running on that machine! I don'rt like my chances of porting the fusionlog viewer to PocketPC!

    Any suggestions?

    Cheers
    Doug

  • Anonymous
    May 07, 2006
    PingBack from http://www.magerquark.de/blog/archive/305

  • Anonymous
    January 24, 2007
    In my time working with .NET, I feel I have only scratched the surface of the multitude of APIs available

  • Anonymous
    February 12, 2007
    TypeLoadException can happen when you have two projects with the same assembly name referenced... had this happen when a vendor assembly had the same name as one of my assemblies. Just thought i'd share.

  • Anonymous
    July 18, 2007
    Hi, Your debugging method help me to diagnose my problem. But now I have question. Can I load two diffrent version of dll (eg. 1.0 and 2.0) to one process? If it is possible, how can I do it? Best regards, Mario

  • Anonymous
    January 03, 2008
    what is the reason for the message: "The located Assembly's manifest definitiondoes not match with the assembly reference" and please give me a solución, thank

  • Anonymous
    August 04, 2008
    How can I catch a StackOverflowException ? I wrote an evaluator in .NET 1.1 migrated to 2.0 and the StackOverflowException can not be caught. So user defined recursions make my application vanish off the screen without any wanings

  • Anonymous
    August 04, 2008
    Maybe I can calculate/retrieve stack depth to prevent this error from occurring? Thank you for your time, Avi

  • Anonymous
    September 12, 2008
    I am running Delphi 2005 NET (still!!) and need to download to an emulator (Windows Mobile 6 Standard) but it keeps giving a TypeLoadException. The Fusion Log doesn't seem to work with (this version of) Delphi. Do you have any comments on how to include Fusion Log in Delphi, or another method of identifying the cause of the exception. Regards

  • Anonymous
    February 20, 2009
    I know this post is a bit old, but thank you so much! Following your steps, I just discovered it was loading an assembly from the GAC and not the bin folder as I thought.  (I'm trying to set up a dev environment of customized software after installing a 'vanilla' version and using this discovered I have multiple versions of DLLs on the machine.)  A life saver!

  • Anonymous
    September 16, 2010
    Meanwhile it's 2010 but I also found this article while searching for MissingMethodException. I'm developing on Windows Phone 7 and I want to share my solution to this exception. It was really hard to debug, but easy to solve. With the Navigate-Method I navigate to a xaml file. Then the exception is thrown. The problem was, that in the corresponding xaml.cs file I had replace the standard constructor by my own one. But you can not navigate to a xaml file, that has no parameterless constructor, as this is needed to instantiate it. And by the way: If you add the defautl constructor, dont forget to call InitializeComponent() in it. Hope this helps