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

当前回答

在我的例子中,MissingMethodException是针对同一个文件中的一个方法!

然而,我刚刚添加了一个使用. net Standard2的NuGet包到我的4.7.1-targeting项目中,这导致了System.Net.Http的版本冲突(4.7.1:版本4.0.0.0,使用. net Standard2的NuGet包需要4.2.0.0)。这似乎是已知的问题,应该更好的4.7.2(见注2)。

我在所有其他项目中都使用了这样的绑定重定向,因为一旦它试图加载4.2.0.0,就会出现异常:

  <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>

除了在这个项目中,它似乎只是在调用使用System.Net.Http.HttpResponseMessage作为参数或返回类型的本地函数时试图加载System.Net.Http(调试期间的参数,在没有调试器的情况下运行测试时的返回类型,这也有点奇怪)。而不是显示消息,它无法加载4.2.0.0版本的System.Net。Http,它返回这个异常。

其他回答

当DLL的旧版本仍然在某个地方徘徊时,就会出现这个问题。确保部署了最新的程序集,并且某些文件夹中没有隐藏重复的旧程序集。最好的办法是删除所有构建的项目,然后重新构建/重新部署整个解决方案。

我在同一个程序集中引用了一个文件,而不是一个单独的dll,就发生了这种情况。一旦我从项目中排除了该文件,然后又将其包含进来,一切都工作得很好。

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项目后,没有生成该项目。

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

我使用了一种在上面的回复中没有提到的方法来解决这个问题。

在我的例子中,调用类方法的项目的目标项目框架设置不正确。

(调用项目的目标框架不正确。被调用的类/方法的目标框架是正确的,我保持不变)。

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