System.MissingMethodException
A MissingMethodException is thrown when code calls a method that the runtime cannot find. The code compiled, so the method existed at build time. At run time, another version of the assembly is loaded, or the method is looked up by name in a way that does not match.
The message gives the full signature of the method that was missing, for example Method not found: 'System.Decimal Shop.Pricing.Calculator.Total(System.Decimal)'. The return type and the parameter types are part of the name.
Minimum version: >= 1.1 >= Core 1.0
Statistics
Common causes
The method that the code was compiled against is not the one that is loaded. These are the usual cases.
A different version of a library at run time
Your code was built against a version of a library that had the method. The deployed version removed it, or changed its parameters or return type. The change in the signature is enough, even if the method has the same name.
Deploy the same versions that you built with, and rebuild your code against the new version if you have updated the library. Check which versions are resolved:
dotnet list package --include-transitive
A class without a parameterless constructor
Activator.CreateInstance and many serializers and frameworks create objects by calling the constructor without arguments. If the class only has a constructor with parameters, the message is No parameterless constructor defined for type.
public class Product
{
public Product(string sku) { Sku = sku; }
public string Sku { get; }
}
Pass the arguments, or add a constructor without parameters if the framework needs one:
public class Product
{
public Product(string sku) { Sku = sku; }
public string Sku { get; }
}
Reflection with a name that does not exist
InvokeMember and similar methods look up a method by name at run time. A typo, a method that was renamed, or a different set of binding flags give this exception. GetMethod returns null instead, which becomes a NullReferenceException later.
var customer = new Customer();
typeof(Customer).InvokeMember("Rename", System.Reflection.BindingFlags.InvokeMethod, null, customer, null); // MissingMethodException
Check the result of GetMethod before you use it, or call the method directly when you can:
var method = typeof(Customer).GetMethod("Rename");
if (method is null)
{
Console.WriteLine("The type has no Rename method.");
}
How to fix it and prevent it
Make build and run time match
Do a clean build and deploy everything from one dotnet publish. Delete the old files in the target folder before you copy the new ones, so no old library is left behind.
Pin the versions of shared packages
When two packages use different versions of the same library, central package management makes the whole solution use one. Then the version you test is the version you ship.
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
</Project>
Avoid breaking changes in your own libraries
If you publish a library, keep the old signature when you add a parameter, and add an overload instead of changing the method. Adding a parameter with a default value does not keep binary compatibility.
public static class Calculator
{
public static decimal Total(decimal amount) => Total(amount, 0m);
public static decimal Total(decimal amount, decimal discount) => amount - discount;
}
How to read the stack trace
The message is the important part. It has the full signature of the method that was not found:
System.MissingMethodException: Method not found: 'System.Decimal Shop.Pricing.Calculator.Total(System.Decimal)'.
at Program.<Main>$(String[] args)
The application calls Calculator.Total(Decimal) from Shop.Pricing, and the loaded version of the library only has Total(Decimal, Decimal). The trace is short because the failure happens when the call is compiled to native code. Look at the version of Shop.Pricing.dll in the deployed folder and compare it with the one you built against.
Should you catch it?
No. It means that the files that were deployed do not match the code. Fix the deployment instead.
For code that loads plugins, you can catch it around the loading of each plugin to keep the others working. Log the signature from the message.
Find MissingMethodException before your users do
elmah.io logs every unhandled exception in your .NET application with its stack trace and request details, groups identical errors and notifies you when a new one appears.
Start free trialRelated exceptions
- TypeLoadException is thrown when a type cannot be loaded, often for the same reason.
- FileNotFoundException is thrown when the assembly is not there at all.
- TargetInvocationException wraps exceptions from methods that are called with reflection.
Frequently asked questions
Why does it work on my machine?
Your machine has the libraries the code was built with. The server has other or older files. Compare the version of the assembly that is named in the message.
What is the difference from MissingMemberException?
MissingMethodException derives from MissingMemberException. A method is missing, and not a field or a property.
Does adding an optional parameter break callers?
Yes, for code that was compiled before. The method has a new signature, so the old call does not find it. Add an overload instead.
How do I see which version was loaded?
Log typeof(SomeType).Assembly.GetName().Version and the Location at startup. A tool such as Process Explorer lists the loaded modules.
Let your AI agent track it down
Connect Claude Code, Cursor, VS Code or Visual Studio to the elmah.io MCP server and ask your agent to look into MissingMethodException for you. For example:
The agent reads the stack trace and request details from elmah.io, finds the code in your repository and proposes a fix. In Claude Code, add the server with one command:
claude mcp add --transport http --client-id claudecode elmahio https://mcp.elmah.io/mcp
The MCP server is included on every plan and is currently in beta. Set up the MCP server.
Further reading
YouTube videos
Answers from Stack Overflow
⚠️ Wrong Nuget Package Version ⚠️
I had a unit test project which was pulling in our companies internal EF Nuget data access package and that code pulled in an external package whose version was way behind the current version.
The issue was that the Nuget settings for the top level package was set to the least version; and the lower level/older version won, and that was used during the operations....
Hence it silently got the wrong version for a common assembly used by both the package and the app.
💡 Solution 💡
By Setting/updating the package in Nuget to use and [get] the latest, fixed the issue.
By ΩmegaMan. Read the original answer on Stack Overflow.
Restarting Visual Studio actually fixed it for me. I'm thinking it was caused by old assembly files still in use, and performing a "Clean Build" or restarting VS should fix it.
By Shoother. Read the original answer on Stack Overflow.
In my case, my class had the [Serializable] attribute.
You are required to have a constructor that takes no parameters if your class is [Serializable]
By Kellen Stuart. Read the original answer on Stack Overflow.
Ran into this error after updating a variety of Nuget packages. Check your Visual Studio Error List (or build output) for a warning similar to the following:
Found conflicts between different versions of the same dependent assembly. In Visual Studio, double-click this warning (or select it and press Enter) to fix the conflicts; otherwise, add the following binding redirects to the "runtime" node in the application configuration file:
...
Double-clicking this warning in Visual Studio automatically adjusted a variety of bindingRedirect package versions in my web.config and resolved the error.
By ElliotSchmelliot. Read the original answer on Stack Overflow.
This may have been mentioned already, but for me the problem was that the project was referencing 2 nuget packages, and each of those nuget packages referenced a different version of another nuget package.
So:
Project -> Nuget A -> Nuget X 1.1
Project -> Nuget B -> Nuget X 1.2
Both versions of Nuget X had the same extension method that was being called from Project.
When I updated both Nuget A & B to versions that referenced the same version of Nuget X, the error went away.
By Shahin Dohan. Read the original answer on Stack Overflow.
Source: Stack Overflow