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 (14)

  1. Mahavir Jain says:

    Suzanne, nice article on MissingMethodException , it helped me debug my problem , Many thanks

  2. ryan groth says:

    dir c:filever.exe /s shows nothing on my machine. I have VS.NET full install. Where do I get filever?

  3. Doug Taylor says:

    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

  4. In my time working with .NET, I feel I have only scratched the surface of the multitude of APIs available

  5. james peckham says:

    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.

  6. Tholrin says:

    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

  7. Novice says:

    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

  8. Avi says:

    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

  9. Avi says:

    Maybe I can calculate/retrieve stack depth to prevent this error from occurring?

    Thank you for your time,

    Avi

  10. pat says:

    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

  11. Jeff says:

    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!

  12. Wolf says:

    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