以前工作的asp.net webforms应用程序现在抛出这个错误:

系统。MissingMethodException:方法未找到

DoThis方法在同一个类上,它应该可以工作。

我有一个通用的处理程序,这样:

public class MyHandler: IHttpHandler
{
    public void Processrequest(HttpContext context)
    {
      // throws error now System.MissingMethodException: 
      // Method not found.
      this.DoThis(); 
    }

    public void DoThis(){ ... }
}

当前回答

我刚刚在一个。net MVC项目中遇到了这个问题。根本原因是NuGet包的版本冲突。我有几个项目的解决方案。每个项目都有一些NuGet包。在一个项目中,我使用了企业库语义日志包的一个版本,而在另外两个项目(引用了第一个项目)中,我使用了同一包的旧版本。它编译时没有错误,但是当我尝试使用这个包时,它给出了一个神秘的“Method not found”错误。

解决办法是从两个项目中删除旧的NuGet包,这样它就只包含在真正需要它的一个项目中。(我也对整个解决方案做了一个干净的重建。)

其他回答

我解决了这个问题,我做了一个搁置我的变化和运行TFS电动工具“烧焦”在我的工作空间(https://visualstudiogallery.msdn.microsoft.com/f017b10c-02b4-4d6d-9845-58a06545627f)。然后我取消了更改并重新编译项目。 这样你就可以清理你工作空间里的“挂着的聚会”,并重新开始一个新的聚会。 当然,这要求您使用TFS。

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.

为了修复这个错误,我必须从DAL更改AnotherProj项目中的引用。CustSpec到只是DAL,删除了临时ASP中的所有文件。NET Files文件夹,然后重新运行网站。从那以后,一切都开始运转了。我还确保了DAL。在“生成配置”中取消选中CustSpec项目后,没有生成该项目。

我想我要分享这个,也许它能在未来帮助到其他人。

你试过把它关掉再打开吗?玩笑归玩笑,重启电脑才是真正让我成功的方法,其他答案中都没有提到。

也有可能问题出在报告丢失的方法的参数或返回类型上,而“丢失”方法本身没有问题。

这就是我的情况,误导性的信息让我花了更长的时间来解决问题。事实证明,用于参数类型的程序集在GAC中有一个较旧的版本,但由于所使用的版本编号方案的更改,旧版本实际上具有更高的版本号。从GAC中删除旧版本/更高版本可以解决这个问题。

在我的例子中,我的项目引用了Microsoft.Net.Compilers.2.10.0。当我把它切换到Microsoft.Net.Compilers.2.7.0时,错误消失了。有这么多原因的一个多么神秘的错误。