System.MissingMethodException: Method not found?

353,134

Solution 1

This is a problem which can occur when there is an old version of a DLL still lingering somewhere around. Make sure that the latest assemblies are deployed and no duplicated older assemblies are hiding in certain folders. Your best bet would be to delete every built item and rebuild/redeploy the entire solution.

Solution 2

⚠️ 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.

Solution 3

I resolved this issue by installing the correct .NET Framework version on the server. The website was running under version 4.0 and the assembly it was calling to was compiled for 4.5. After installation of .NET Framework 4.5 and upgrading the website to 4.5, all works fine.

Solution 4

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.

Solution 5

Check your References!

Be sure that you are consistently pointing to the same 3rd party libraries (don't just trust versions, look at the path) across your solutions projects.

For example, If you use iTextSharp v.1.00.101 in one project and you NuGet or reference iTextSharp v1.00.102 somewhere else you will get these types of runtime errors that somehow trickle up into your code.

I changed my reference to iTextSharp in all 3 projects to point to the same DLL and everything worked.

Share:
353,134

Related videos on Youtube

user603007
Author by

user603007

Updated on July 08, 2022

Comments

  • user603007
    user603007 almost 2 years

    Previous working asp.net webforms app now throws this error:

    System.MissingMethodException: Method not found

    The DoThis method is on the same class and it should work.

    I have a generic handler as such:

    public class MyHandler: IHttpHandler
    {
        public void Processrequest(HttpContext context)
        {
          // throws error now System.MissingMethodException: 
          // Method not found.
          this.DoThis(); 
        }
    
        public void DoThis(){ ... }
    }
    
    • mironych
      mironych over 12 years
      can you post some more code, because this code is not valid.
    • Admin
      Admin over 12 years
      What is somepage? As 'sound' noted, this code isn't valid. Please give us a complete code snippet that demonstrates the problem.
    • Taraz
      Taraz over 2 years
      If you're encountering this error when running locally on your machine, try recompiling with the optimizeCompilations key set to false in your web.config.
  • ladenedge
    ladenedge almost 12 years
    In particular, be sure an old version is not in the GAC.
  • Serj Sagan
    Serj Sagan over 10 years
    Also, if you're working in the unfortunate case where you have a library that depends on a library, that depends on a library, etc. Then make sure to Clean/Rebuild all of the dependent libraries with the same version of whichever dll, NHibernate in my case...
  • Martin Meeser
    Martin Meeser about 10 years
    some problem with .NET 3.5 compile target and installed .NET 3. I really wonder why there is no more basic warning at startup...
  • SerG
    SerG about 10 years
    How should I check it?
  • sennett
    sennett about 10 years
    I think in the nupkg.
  • Lukas S.
    Lukas S. over 9 years
    Upgrading the .NET target framework for the project can also fix the error. I was upgrading an MVC4 / Web API 1 project targeting .NET 4.5. After upgrading all the MVC, Web API, and Entity Framework dependencies, I ran into the same error; changing the target framework to .NET 4.5.1 made the error go away.
  • fbastian
    fbastian over 8 years
    In case you are using TFS, you can download TFS Power Tools (visualstudiogallery.msdn.microsoft.com/…) and run a 'scorch' in your workspace. It will make sure that your workspace is identical to the repository, cleaning up any 'hanging-parties'. Remember to shelve your changes before running the scorch so you can unshelve them again after.
  • Ho Ho Ho
    Ho Ho Ho over 8 years
    It happened to me when I deployed only a changed exe file and did not deploy a helper dll because it had not had any code change - but it had been re-built. I deployed that rebuilt dll and the error went away. I've done other deployments without re-deploying an otherwise unchanged dll and had no issues so I'm still not sure exactly what happened here. I guess the safe thing to do is deploy any rebuilt file no matter if it has underlying code changes or not.
  • aoakeson
    aoakeson almost 8 years
    This fixed it for me. Managing the packages for the solution didn't work, but I had to update each project individually.
  • bgcode
    bgcode almost 7 years
    For .NET Framework version > 4.0, you need to specify the stock-keeping unit (SKU),it indicates the version of the .NET Framework that the app targets. docs.microsoft.com/en-us/dotnet/framework/configure-apps/…
  • Dan Rayson
    Dan Rayson over 6 years
    Don't forget to check across ALL of the projects in your solution!
  • DaBeSoft
    DaBeSoft over 6 years
    @RenaudGauthier maybe i misread something at Jon Skeets answer, but he states that classes with no access modifier are internal, and in the comments he literally states "No it's not. If you declare a constructor and don't specify an accessibility, it will be private. See section 10.3.5 of the C# spec". So i guess my constructor is private after all? Please correct me if i am mistaken. And yes my answeer was out of context, i came here from another Question (which didn't provide an answer for me). I will add a link to my answer there too.
  • Renaud Gauthier
    Renaud Gauthier over 6 years
    You are absolutely right, nevermind me, I've deleted the useless comment.
  • JamesD
    JamesD over 6 years
    I found it useful to open the Debug -> Windows -> Modules window when debugging to see where the assembly was being loaded from.
  • Rhyous
    Rhyous over 6 years
    My unit test project was referencing a new version than my actual project
  • chris c
    chris c almost 6 years
    In my case there was a dll from plugin-a in a plugin-b folder which wasn't even supposed to be there in the first place. So when I updated plugin-a the dll in plugin-b was out dated. The dll can end up in a plugin when you add reference but don't set copy local to false.
  • Honza P.
    Honza P. over 5 years
    For me it worked well to Clean project and delete and Add some references once again.
  • rory.ap
    rory.ap over 5 years
    I've been dinged by the GAC issue numerous times, as evidenced by my having already up-voted @ladenedge's comment at some point in the past when I just "discovered" this answer again.
  • Mr. TA
    Mr. TA over 5 years
    This is particularly a problem with VS 2017 because it often offers you to add a reference which sets the source path to the output folder of another project in the solution, not the output folder of the reference assembly.
  • Sameer
    Sameer almost 4 years
    The answer I was looking fr, 1 version difference between unit test and main project, was giving me the error. Updated to the same version and that worked
  • JimiSweden
    JimiSweden over 3 years
    In my case I had the same message and this post pointed me in the right direction. This is to add some info for those of you running dotnet standard (netstandard), and .Net Framework (net40). The problem for me unfortunatly was that the net40 application using the netstandard library, got a nuget package with incompatible API, so, "the same" nuget package is used, but implementaion differs. See my write up here jimi.se/…
  • user1867382
    user1867382 over 3 years
    I've just had this because our installer version didn't increment and so while it looked like the new app was installed, the old DLLs must have been in the GAC or somewhere, being used instead of the newly installed app.
  • Jack
    Jack about 2 years
    Same with Costura.Fody 4.1.0
  • For Comment
    For Comment almost 2 years
    It happened for my ZedGraph.dll reference, I found there was a module loaded from C:\Windows\assembly\GAC_MSIL\ZedGraph\5.1.5.28844__02a83cbd1‌​23fcd60\ZedGraph.dll‌​, in addition to the specific ZedGraph.dll I reference in my own project, so after deleting the one in the C:\Windows\assembly folder, the problem went away.
  • FernandoG
    FernandoG almost 2 years
    Yeah I had two projects in one solution referencing the same model from a pckg but the nuget packages were different in each.