Unable to load one or more of the requested types - Method does not have an implementation error

Oct 2, 2009 at 7:26 PM

Hi, I think this is a pretty newbie error , but I have been stuck with this for quite some time. I shall provide the scenario first and then explain the error. Hope someone can help:

 

The solution is separated into 3 projects: 

1) Project containing simply the Common Interfaces 

2) Plugins/Components implementing the Common Interfaces[project 1]

3) Shell Project loading the Plugins [Project 2] from a directory during runtime with the help of Common Interfaces [Project 1]

In Project 1 , I have defined two Interfaces

 

/*********************************************************/
namespace ServiceInterface.AsteriskService
{
    public interface IAsteriskService
    {
              
        IAsteriskEventOriginator GetAsteriskEventOriginator();      
    }
}
/**************************************************/
 namespace ServiceInterface.AsteriskService

 {

public interface  IAsteriskEventOriginator
    {

        ManagerResponse RetrivePeers();

    }
}

/***************************************************************/

 


Now, in Project 2 , I implement those two Interfaces in two classes and then export the class Implementing IAsteriskService

/***************************************************************/ 
public class AsteriskEventOriginator :  IAsteriskEventOriginator
 {
	/*Implementation of the method that throws Method does not have an implementation */
public ManagerResponse RetrivePeers() { return new ManagerResponse(); } }
/***************************************************************/

[Export(typeof (IAsteriskService))]
public class Asterisk :  IAsteriskService
 {
       

        public IAsteriskEventOriginator GetAsteriskEventOriginator()
        {
            return  new EventOriginator();
        }
}
/***************************************************************/
Finally , in project 3 (Shell project) , I try to load the plugin (Asterisk ) and compose using the following method:
/***************************************************************/
public void Compose()
        {
            var catalog = new AggregatingComposablePartCatalog();
            try
            {
                catalog.Catalogs.Add(new DirectoryPartCatalog(@"PluginDirectoryOfProject2"));
                catalog.Catalogs.Add(new AttributedAssemblyPartCatalog(Assembly.GetExecutingAssembly()));
                var container = new CompositionContainer(catalog.CreateResolver());
                container.AddPart(this);
                container.Compose();
 	    }
            catch (ReflectionTypeLoadException e)
            {
                
            }
   }
/***************************************************************/
Now when I try to Run it , it throws an error at this line:
	
catalog.Catalogs.Add(new DirectoryPartCatalog(@"PluginDirectoryOfProject2"));

The error is: 
{"Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information."}	System.Reflection.ReflectionTypeLoadException
Upon further inspection into the LoaderExceptions using debugger , I track it down to the following:

"Method 'RetrivePeers' in type 'AsteriskService.AsteriskEventOriginator' from assembly 'AsteriskService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation."
Which is rather confusing , because in AsteriskEventOriginator , I HAVE implemented RetrivePeers().

I suspected the error is with adding reference to some assembly . But adding reference to all the projects and assemblies has still not solved the problem.

Does anyone have any idea ?

regards,
Shrouk Khan

 

 

 

 

 

 

 

Oct 2, 2009 at 8:10 PM

Hi Shrouk

One cause of this would be if there is an old reference to your common interfaces project hanging around. I'd double check to see that all references are pointing to the same place, otherwise a different version of the interface may be getting picked up at runtime which would cause the error.  Do you have an older version of the common interfaces assembly in your plugin folder?

Glenn

Oct 9, 2009 at 4:47 AM

Hi, i think you were right. it was obviously looking at different place to pick up the dlls. however, i could not solve that problem. What i had to do is integrate the project 1 (shared interfaces) into the main shell project (project 3) and it solved the problem.