简体   繁体   English

System.TypeLoadException:方法“get_xxx”没有实现

[英]System.TypeLoadException: Method 'get_xxx' does not have an implementation

There are a lot of questions floating around with this problem and i've worked through them ll with no joy.有很多关于这个问题的问题,我已经毫无乐趣地解决了它们。

I am receiving this error:我收到此错误:

Method 'get_UserImageCDNUrl' in type 'App.Web.WebConfig' from assembly 'App.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.来自程序集“App.Web,版本=1.0.0.0,文化=中性,PublicKeyToken=null”的“App.Web.WebConfig”类型中的方法“get_UserImageCDNUrl”没有实现。

Which is really strange because I am trying to run Api.Web which has no reference to App.Web, the only thing they have in common are references to other projects (Models.Domain and Models.DTO).这真的很奇怪,因为我正在尝试运行没有引用 App.Web 的 Api.Web,它们唯一的共同点是对其他项目(Models.Domain 和 Models.DTO)的引用。

I have an interface:我有一个界面:

IResourceCompiler in an assembly "Models.Domain"程序集“Models.Domain”中的IResourceCompiler

I have an abstract class which implements this interface in the same assembly (Models.Domain) called WebConfigBase我有一个抽象类,它在名为WebConfigBase的同一个程序集(Models.Domain)中实现了这个接口

In the "App.Web" and "Api.Web" projects they each have a class called WebConfig which inherit from WebConfigBase , therefore both WebConfig classes in App and Api are implementations of IResourceCompiler .在“App.Web”和“Api.Web”项目中,它们每个都有一个名为WebConfig的类,它继承自WebConfigBase ,因此 App 和 Api 中的WebConfig类都是IResourceCompiler 的实现。

I tried to add a property我试图添加一个属性

string UserImageCDNUrl {get;}

to IResourceCompiler and added the property to WebConfigBaseIResourceCompiler并将属性添加到WebConfigBase

public string UserImageCDNUrl 
{
    get { return ""; } 
}

so the property would be accessible to both Api and Web projects through their own WebConfig classes, and i get the exception above.因此 Api 和 Web 项目都可以通过它们自己的WebConfig类访问该属性,并且我得到了上面的异常。

I have looked for hours to try and see why this happens with no joy.我已经找了几个小时来尝试看看为什么会发生这种情况而没有快乐。

I've cleared my Obj folders, cleaned, rebuilt, checked for any instances in GAC (there aren't any) and i'm still stuck on this.我已经清除了我的 Obj 文件夹、清理、重建、检查了 GAC 中的任何实例(没有任何实例),但我仍然坚持这一点。

Everything works fine until i try to add a new property to the interface (and base class)一切正常,直到我尝试向接口(和基类)添加新属性

OK, so bizarrely adding a reference to App.Web in Api.Web and removing it again has solved the issue.好的,奇怪的是,在 Api.Web 中添加对 App.Web 的引用并再次删除它已经解决了问题。

I have no idea why, but it did.我不知道为什么,但确实如此。

I changed the version of App.Web to 1.0.0.1 and the error was still showing 1.0.0.0, which is what prompted me to do it.我将 App.Web 的版本更改为 1.0.0.1 并且错误仍然显示 1.0.0.0,这就是促使我这样做的原因。

I wish there was a more reasonable explanation but there isn't.我希望有一个更合理的解释,但没有。 Such an infuriating issue i'm just glad to be done with it.这么令人气愤的问题,我很高兴能解决它。

Best of luck to anyone else who experiences this, my thought's are with you祝遇到这种情况的其他人好运,我的想法与你同在

For the records, in my case this was caused by two projects referencing different versions of the same package.作为记录,在我的情况下,这是由引用同一包的不同版本的两个项目引起的。 At least fixing this solved the issue.至少解决这个问题解决了这个问题。

There can be many reasons for this, all the previous answers represent a case of this problem.造成这种情况的原因可能有很多,之前的所有答案都代表了这个问题的一个案例。

What I suggest doing is:我建议做的是:
while your program is running open Resource Monitor -> CPU tab and in the search handles input box, search for the assembly that supposedly doesn't implement that method.当您的程序运行时,打开 Resource Monitor -> CPU 选项卡并在搜索句柄输入框中,搜索据称未实现该方法的程序集。

In the search results you'll see the path of your assembly, and most likely the path that you see isn't the one that you expect.在搜索结果中,您将看到程序集的路径,而且您看到的路径很可能不是您期望的路径。
Delete the assembly from this unexpected path so that the correct assembly gets loaded.从此意外路径中删除程序集,以便加载正确的程序集。

In many cases I become this error.在许多情况下,我会成为这个错误。 It seems like Cached assembly and I found them in UserProfile.看起来像缓存程序集,我在 UserProfile 中找到了它们。

My solution is:我的解决办法是:

  1. Save solution and close Visual Studio保存解决方案并关闭 Visual Studio
  2. Delete entire folder "c:\\Users(user)\\AppData\\Local\\Microsoft\\VisualStudio\\14.0\\ProjectAssemblies\\"删除整个文件夹“c:\\Users(user)\\AppData\\Local\\Microsoft\\VisualStudio\\14.0\\ProjectAssemblies\\”
  3. Start Visual Studio启动 Visual Studio
  4. Work...工作...

Hope it helps.希望它有帮助。

I just remove the reference of current project (which is showing error) , and add again to other project in which project this was referenced build and it start working fine.我只是删除了当前项目的引用(显示错误),然后再次添加到其他项目中,该项目在该项目中引用了 build 并且它开始正常工作。

hope this help someone.希望这有助于某人。

try this试试这个

public interface IResourceCompiler
{
    string UserImageCDNUrl {get;}
}

public abstract class WebConfigBase : IResourceCompiler
{
    public abstract string UserImageCDNUrl {get;}
}

public class WebConfig : WebConfigBase 
{
    public override string  UserImageCDNUrl { return "whatever you want";}
}

or that way too:或者也这样:

public interface IResourceCompiler
{
    string UserImageCDNUrl {get;}
}

public abstract class WebConfigBase : IResourceCompiler
{
    public virtual string UserImageCDNUrl {get { return string.empty;}}
}

public class WebConfig : WebConfigBase 
{
    public override string  UserImageCDNUrl { return "whatever you want";} // or return base.UserImageCDNUrl ;
}

I was seeing this problem in Visual Studio 2017.我在 Visual Studio 2017 中看到了这个问题。

Upgrading to visual studio 2019 solved the problem for me.升级到 Visual Studio 2019 为我解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Castle Keeps给我一个System.TypeLoadException:方法'myMethod'没有实现? - Castle Keeps giving me a System.TypeLoadException: Method 'myMethod' does not have implementation? System.TypeLoadException:get_TargetFramework没有实现 - System.TypeLoadException: get_TargetFramework doesn't have an implementation 程序集“ myAssembly”中类型为“ MyNamespace.MyType”的System.TypeLoadException方法“ GetX”没有实现 - System.TypeLoadException Method 'GetX' in type 'MyNamespace.MyType' from assembly 'myAssembly' does not have an implementation OnConfiguring方法上的System.TypeLoadException - System.TypeLoadException at OnConfiguring method 未处理System.TypeLoadException:无法加载类型,因为该方法没有实现(没有RVA) - System.TypeLoadException was unhandled: Could not load type because the method has no implementation (no RVA) TypeLoadException方法“设置”没有实现 - TypeLoadException Method 'Set' does not have an implementation 麻烦的System.TypeLoadException - Troublesome System.TypeLoadException System.TypeLoadException - System.TypeLoadException 错误:System.TypeLoadException - Error: System.TypeLoadException DropShadow的System.TypeLoadException - System.TypeLoadException for DropShadow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM