Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# "Method not found" exception on runtime without usage of reflection

Tags:

c#

.net

I have a problem with getting above exception. I have a relatively simple structure separate in two dll.

First one contains a IEntityService, IEntity, with basic implementation. 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. Similar situation happen for a Result collection( entity plus service). 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. However when I am trying to save I got the "Method not found" when trying to access a saving method from a EntityService class. However if I wrap EntityService.Save method in a MachineService it is working without any exception.

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. What is more it is not strongly signed, the only difference is version number.

like image 705
Assassin Avatar asked Sep 30 '10 18:09

Assassin


1 Answers

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)
  • deploy program dll to 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.

Some times it uses a cached version of the old dll, IISreset can help.

In your case check for any old versions of the dll.

like image 131
Shiraz Bhaiji Avatar answered Oct 18 '22 17:10

Shiraz Bhaiji