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

当前回答

我也有同样的事情发生,当我有许多MSBuild进程在后台运行时,它们实际上已经崩溃了(它们引用了旧版本的代码)。我关闭VS并在进程资源管理器中杀死所有MSBuild进程,然后重新编译。

其他回答

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

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

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

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

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

我遇到了这个问题,对我来说,它是一个项目,在例子中使用一个列表。传感器命名空间和另一种类型实现了ISensorInfo接口。类Type1SensorInfo,但是这个类在Example.Sensors.Type1的命名空间中更深一层。当试图将Type1SensorInfo反序列化到列表中时,会抛出异常。当我使用Example.Sensors添加时。输入1到ISensorInfo接口,没有更多的异常!

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() 
    }
}

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

重新启动Visual Studio实际上为我解决了这个问题。我认为这是由于旧的程序集文件仍然在使用造成的,执行“清洁构建”或重新启动VS应该会修复它。