tags:

views:

93

answers:

3

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.

A: 

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'

Kristopher Johnson
+1  A: 

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.

Shiraz Bhaiji
+1  A: 

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?

Bryce Fischer