TransWikia.com

System.MissingMethodException: Method not found?

Stack Overflow Asked by user603007 on December 13, 2020

What once was working in my 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()
    {
    //
    }
}

34 Answers

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.

Correct answer by Polity on December 13, 2020

I got this exception while testing out some code a coworker had written. Here is a summary of the exception info.:

Method not found: "System.Threading.Tasks.Task1<Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry1<System_Canon>> Microsoft.EntityFrameworkCore.DbSet`1.AddAsync...

This was in Visual Studio 2019 in a class library targeting .NET Core 3.1. The fix was to use the Add method instead of AddAsync on the DbSet.

Answered by Chuck Smith on December 13, 2020

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.

Answered by ElliotSchmelliot on December 13, 2020

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.

Answered by Shahin Dohan on December 13, 2020

In my case, the MissingMethodException was for a method that was in the same file!

However, I had just added a NuGet package that uses .Net Standard2 to my 4.7.1-targeting project, which caused a version conflict for System.Net.Http (4.7.1: version 4.0.0.0, the NuGet package using .NET Standard 2 wants 4.2.0.0). This seem to be known issues that should be better in 4.7.2 (see note 2).

I had used a binding redirect like this in all other my projects, because there were exceptions as soon as it tried to load the 4.2.0.0 which I didn't have:

  <dependentAssembly>
    <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.0.0.0" />
  </dependentAssembly>

Except in this one project, where it seems it tries to load System.Net.Http only while calling a local function that uses a System.Net.Http.HttpResponseMessage as it's parameter or return type (parameter during debugging, return type when I run the tests without the debugger, also a bit strange). And instead of showing a message that it could not load the 4.2.0.0 version of System.Net.Http, it returns this exception.

Answered by Legolas on December 13, 2020

For posterity, I ran into this with an azure function, using the azure durable function / durable tasks framework. It turns out I had an outdated version of the azure functions runtime installed locally. updating it fixed it.

Answered by jkerak on December 13, 2020

In case the problem is caused by an old version of the assembly in the GAC.
This can help: How to: Remove an Assembly from the Global Assembly Cache.

Answered by Ymagine First on December 13, 2020

In my case it was a folder with olders DLLs of the same name that those wich were referenced in my .csproj file although the path was explicitly given they were somehow included therefore the several versions of the same DLLs were in conflict.

Answered by Alexandre Daubricourt on December 13, 2020

In my case, my project was referencing Microsoft.Net.Compilers.2.10.0. When I switched it to Microsoft.Net.Compilers.2.7.0, the error went away. What a mysterious error with such a variety of causes.

Answered by jaycer on December 13, 2020

Must be a reference bug from Microsoft.

I cleaned, rebuild on all my libraries and still got the same problem and couldnt resolve this.

All i did was close the Visual Studio Application and opened it again. That did the trick.

Its very frustrating that such a simple issue can take that long to fix because you wouldnt think that it will be something like that.

Answered by JayJay Barnard on December 13, 2020

In my case, there was no code change at all and suddenly one of the servers started getting this and only this exception (all servers have the same code, but only one started having issues):

System.MissingMethodException: Method not found: '?'.

Stack:

Server stack trace: 
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at myAccountSearch.AccountSearch.searchtPhone(searchtPhoneRequest request)
   at myAccountSearch.AccountSearchClient.myAccountSearch.AccountSearch.searchtPhone(searchtPhoneRequest request)
   at myAccountSearch.AccountSearchClient.searchtPhone(String ID, String HashID, searchtPhone Phone1)
   at WS.MyValidation(String AccountNumber, String PhoneNumber)

The issue I believe was corrupted AppPool - we have automated AppPool recycling going on every day at 3 am and the issue started at 3 am and then ended on its own at 3 am the next day.

Answered by George on December 13, 2020

I had this problem when the method required a parameter that I was not specifying

Answered by Lord Darth Vader on December 13, 2020

Using Costura.Fody 1.6 & 2.0:
After wasting a bunch of time looking into this same kind of error with all other potential solutions not working, I found that an older version of the DLL I was embedding was in the same directory I was running my newly compiled .exe from. Apparently it looks for a local file in the same directory first, then looks inward to its embedded library. Deleting the old DLL worked.

To be clear, it wasn't that my reference was pointing to an old DLL, it was that a copy of an old DLL was in the directory I was testing my application from on a separate system from that which it was compiled on.

Answered by grep65535 on December 13, 2020

In my case it was a copy/paste problem. I somehow ended up with a PRIVATE constructor for my mapping profile:

using AutoMapper;

namespace Your.Namespace
{
    public class MappingProfile : Profile
    {
        MappingProfile()
        {
            CreateMap<Animal, AnimalDto>();
        }
    }
}

(take note of the missing "public" in front of the ctor)

which compiled perfectly fine, but when AutoMapper tries to instantiate the profile it can't (of course!) find the constructor!

Answered by DaBeSoft on December 13, 2020

It's also possible the problem is with a parameter or return type of the method that's reported missing, and the "missing" method per se is fine.

That's what was happening in my case, and the misleading message made it take much longer to figure out the issue. It turns out the assembly for a parameter's type had an older version in the GAC, but the older version actually had a higher version number due to a change in version numbering schemes used. Removing that older/higher version from the GAC fixed the problem.

Answered by Jimmy on December 13, 2020

In my case spotify.exe was using the same port which my web api project wanted to use on a development machine. The port number was 4381.

I quit Spotify and everything worked well again :)

Answered by Arda Basoglu on December 13, 2020

I had a test project that references 2 other projects that each referenced different versions (in different locations) of the same dll. This confused the compiler.

Answered by nuander on December 13, 2020

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.

Answered by Juls on December 13, 2020

I've just had this issue and it turned out that it was because I was referencing a previous version of the DLL from my UI project. Therefore, when compiling it was happy. But when running it was using the previous version of the DLL.

Check references on all other projects before assuming you need to rebuild/clean/redeploy your solutions.

Answered by Jamie Lupton on December 13, 2020

⚠️ 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 package was set to the least version; and the older version won and was used during 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.

Answered by ΩmegaMan on December 13, 2020

I've had the same thing happen when I had a number of MSBuild processes running in the background which had effectively crashed (they had references to old versions of code). I closed VS and killed all the MSBuild processes in process explorer and then recompiled.

Answered by bytedev on December 13, 2020

I solved this problem by making a shelveset with my changes and running TFS Power Tools 'scorch' in my workspace (https://visualstudiogallery.msdn.microsoft.com/f017b10c-02b4-4d6d-9845-58a06545627f). Then I unshelved the changes and recompiled the project. This way you will cleanup any 'hanging-parties' that may be around in your workspace and will startup with a fresh one. This requires, of course, that you are using TFS.

Answered by fbastian on December 13, 2020

I ran into this issue, and what it was for me was one project was using a List which was in Example.Sensors namespace and and another type implemented the ISensorInfo interface. Class Type1SensorInfo, but this class was one layer deeper in the namespace at Example.Sensors.Type1. When trying to deserialize Type1SensorInfo into the list, it threw the exception. When I added using Example.Sensors.Type1 into the ISensorInfo interface, no more exception!

namespace Example
{
    public class ConfigFile
    {
        public ConfigFile()
        {
            Sensors = new List<ISensorInfo<Int32>>();
        }
        public List<ISensorInfo<Int32>> Sensors { get; set; }
     }
   }
}

**using Example.Sensors.Type1; // Added this to not throw the exception**
using System;

namespace Example.Sensors
{
    public interface ISensorInfo<T>
    {
        String SensorName { get; }
    }
}

using Example.Sensors;

namespace Example.Sensors.Type1
{
    public class Type1SensorInfo<T> : ISensorInfo<T>
    {
        public Type1SensorInfo() 
    }
}

Answered by Steven Koxlien on December 13, 2020

I came across the same situation in my ASP.NET website. I deleted the published files, restarted VS, cleaned and rebuild the project again. After the next publish, the error was gone...

Answered by Irshu on December 13, 2020

Just in case it helps anyone, although it's an old issue, my problem was a bit odd.

I had this error while using Jenkins.

Eventually found out that the system date was manually set to a future date, which caused dll to be compiled with that future date. When the date was set back to normal, MSBuild interpreted that the file was newer and didn't require recompile of the project.

Answered by Renato Chencinski on December 13, 2020

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.

Answered by Jelani on December 13, 2020

This happened to me using MVC4, and I decided after reading this thread to rename the object that was throwing the error.

I did a clean and rebuild and noted that it was skipping two projects. When I rebuilt one of them, there was an error where I'd started a function and not finished it.

So VS was referencing a model that I had rewritten without asking me if I wanted to do that.

Answered by TheWizardOfTN on December 13, 2020

I just ran into this on a .NET MVC project. The root cause was conflicting versions of NuGet packages. I had a solution with several projects. Each of the projects had some NuGet packages. In one project I had a version of the Enterprise Library Semantic Logging package, and in two other projects (that reference the first) I had older versions of the same package. It all compiles without error, but it gave a mysterious "Method not found" error when I tried to use the package.

The fix was to remove the old NuGet packages from the two projects, so that it was only included in the one project that actually needed it. (Also I did a clean rebuild of the whole solution.)

Answered by Mark Meuer on December 13, 2020

Have you tried turning if off and on again? Jokes aside, restarting my computer was what actually did the trick for me and isn't mentioned in any of the other answers.

Answered by Lee Bailey on December 13, 2020

also.. try to "clean" your projects or solution and rebuild again!

Answered by user384080 on December 13, 2020

If developing with your own NuGet server, make sure the assembly versions are all the same:

[assembly: AssemblyVersion("0.2.6")]
[assembly: AssemblyFileVersion("0.2.6")]
[assembly: AssemblyInformationalVersion("0.2.6")]

Answered by sennett on December 13, 2020

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.

Answered by Ben Gripka on December 13, 2020

I had a similar scenario where I was getting this same exception being thrown. I had two projects in my web application solution, named, for sake of example, DAL and DAL.CustSpec. The DAL project had a method named Method1, but DAL.CustSpec did not. My main project had a reference to the DAL project and also a reference to another project named AnotherProj. My main project made a call to Method1. The AnotherProj project had a reference to the DAL.CustSpec project, and not the DAL project. The Build configuration had both the DAL and DAL.CustSpec projects configured to be built. After everything was built, my web application project had the AnotherProj and DAL assemblies in its Bin folder. However, when I ran the website, the Temporary ASP.NET folder for the website had the DAL.CustSpec assembly in its files and not the DAL assembly, for some reason. Of course, when I ran the part that called Method1, I received a "Method not found" error.

What I had to do to fix this error was to change the reference in the AnotherProj project from DAL.CustSpec to just DAL, deleted all the files in the Temporary ASP.NET Files folder, and then reran the website. After that, everything started working. I also made sure that the DAL.CustSpec project was not being built by unchecking it in the Build Configuration.

I thought I would share this in case it helps someone else in the future.

Answered by Ron Kanagy on December 13, 2020

I had this happen to me with a file referenced in the same assembly, not a separate dll. Once I excluded the file from the project and then included it again, everything worked fine.

Answered by Josh Noe on December 13, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP