简体   繁体   English

没有使用反射的运行时C#“找不到方法”异常

[英]C# “Method not found” exception on runtime without usage of reflection

I have a problem with getting above exception. 我遇到上述异常的问题。 I have a relatively simple structure separate in two dll. 我有一个相对简单的结构,分为两个dll。

First one contains a IEntityService, IEntity, with basic implementation. 第一个包含IEntityService,IEntity,具有基本实现。 Second one contains the actual implementations as well as interfaces. 第二个包含实际的实现以及接口。 so there is a IMachine service which implements IEntityService and MachineService which implements both IEntityService and EntityService. 所以有一个IMachine服务实现IEntityService和MachineService,它实现了IEntityService和EntityService。 Similar situation happen for a Result collection( entity plus service). 类似的情况发生在Result集合(实体加服务)上。 Additionally the service(Machine and result) are partial classes/interfaces where one of the class is auto generated. 此外,服务(机器和结果)是部分类/接口,其中一个类是自动生成的。

Now in one of the ResultMachine I am trying to get a machine and in a case it do not exists I am creating it and saving. 现在在ResultMachine中的一个我试图获得一台机器,如果它不存在,我正在创建它并保存。 However when I am trying to save I got the "Method not found" when trying to access a saving method from a EntityService class. 但是,当我尝试保存时,尝试从EntityService类访问保存方法时,我得到了“找不到方法”。 However if I wrap EntityService.Save method in a MachineService it is working without any exception. 但是,如果我在MachineService中包装EntityService.Save方法,它可以正常工作。

Edited: 编辑:

The code is not required. 代码不是必需的。 THe resolution was to re-link the reference. 决议是重新链接参考。 What was misleading for me that my dll is not in GAC, it is linked with VS. 什么误导我,我的dll不在GAC中,它与VS有关。 What is more it is not strongly signed, the only difference is version number. 更重要的是它没有强烈签名,唯一的区别是版本号。

We have got this error a few times, you can recreate the problem as follows: 我们有几次出现此错误,您可以按如下方式重新创建问题:

  • Created project with 2 dll's (say a program dll and a test dll) 使用2个dll创建项目(比如一个程序dll和一个测试dll)
  • deploy program dll to GAC 将程序dll部署到GAC
  • Add new method 添加新方法
  • Create test to test the new method 创建测试以测试新方法
  • build solution 构建解决方案
  • run test (not in debug mode) 运行测试(不在调试模式下)

You will now get the method missing exception. 您现在将获得缺少异常的方法。 The reason is that it is using the old version of the dll that is in GAC and does not have the method. 原因是它使用的是GAC中的旧版本的dll而没有该方法。

Some times it uses a cached version of the old dll, IISreset can help. 有时它使用旧版DLL的缓存版本,IISreset可以提供帮助。

In your case check for any old versions of the dll. 在您的情况下检查任何旧版本的DLL。

My first instinct would be to check to make sure the assemblies contained the classes with the missing method. 我的第一直觉是检查以确保程序集包含缺少方法的类。 I suppose its possible that the assembly didn't get updated immediately? 我想有可能装配没有立即更新?

When referencing the "same" type from different assemblies, make sure you are loading everything via the same path. 从不同的程序集引用“相同”类型时,请确保通过相同的路径加载所有内容。 Otherwise, identical types can actually be treated as if they are different. 否则,实际上可以将相同类型视为不同。

See this article for more: Fusion Loader Contexts - Unable to cast object of type 'Whatever' to type 'Whatever' 有关更多内容,请参阅此文章: Fusion Loader上下文 - 无法输入“Whatever”类型的对象来键入“Whatever”

This happened to me when I went in and tweaked my build settings to output to /bin/Debug rather than to just /bin in a case when I was also using IIS to host the site from the dev folder. 当我进入并调整我的构建设置以输出到/ bin / Debug而不是仅仅/ bin时,当我还使用IIS从dev文件夹托管站点时,这发生在我身上。

You need to have the binaries in the same folder as the service, in my case, and the tweak left old versions in the bin folder and put subsequent builds into the /bin/Debug folder (and /bin/Release). 在我的情况下,您需要将二进制文件放在与服务相同的文件夹中,并在bin文件夹中调整左侧旧版本,并将后续版本放入/ bin / Debug文件夹(和/ bin / Release)。

Either keep the settings as is and have a post build action to copy the bits up one level, have different IIS applications for debug/release, or deploy to another folder altogether. 保持设置不变并进行后置构建操作以将位复制到一个级别,具有不同的IIS应用程序以进行调试/发布,或者完全部署到另一个文件夹。 The latter is probably most "correct" but for my purposes I just realized after much wheel-spinning, that I had different versions in the service's folder. 后者可能是最“正确的”,但就我的目的而言,我刚刚实现了轮转,我在服务的文件夹中有不同的版本。 HTH. HTH。

In my case I just deployed on a machine with .NET 3.0 (Windows XP) while the compile target has been .NET 3.5. 在我的情况下,我刚刚部署在一台装有.NET 3.0(Windows XP)的机器上,而编译目标是.NET 3.5。

This error message is really not helpful. 此错误消息实际上没有用。

Problem has been usage of DataContract from System.Runtime.Serialisation. 问题一直是从System.Runtime.Serialisation使用DataContract。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM