以前工作的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(){ ... }
}

当前回答

检查你的推荐信!

确保在解决方案项目中始终指向相同的第三方库(不要只信任版本,要查看路径)。

例如,如果你在一个项目中使用iTextSharp v.1.00.101,你在其他地方NuGet或引用iTextSharp v1.00.102,你会得到这些类型的运行时错误,以某种方式渗透到你的代码。

我在所有3个项目中更改了对iTextSharp的引用,以指向相同的DLL,一切都正常工作。

其他回答

如果使用自己的NuGet服务器开发,请确保程序集版本都相同:

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

也. .尝试“清理”您的项目或解决方案并重新构建!

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中删除旧版本/更高版本可以解决这个问题。

使用Costura。Fody 1.6 & 2.0: 在浪费了大量时间寻找所有其他潜在解决方案都不起作用的类似错误之后,我发现我嵌入的一个旧版本的DLL位于我运行新编译的.exe的同一目录中。显然,它首先在同一目录中查找本地文件,然后向内查找其嵌入式库。删除旧的DLL起作用了。

需要明确的是,我的引用并不是指向一个旧的DLL,而是旧DLL的副本位于我测试应用程序的目录中,该目录与编译应用程序的系统不同。