469,934 Members | 1,844 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

Problem loading a Plugin that implements an interface

hi,

I'm having a problem with plugins....as follows:
I have 3 projects: 2 class libraries and 1 Windows App

(Project 1: ClassLibrary)
I have a plugin interface:
--------------------------------------------------------------------
namespace API
{
public interface IPlugin
{
string GetPluginName(); // returns the plugin name
void Setup(); // displays the configuration
form
}
}

(Project 2: ClassLibrary)
a plugin class that implements the interface:
a plugin configuration form:
--------------------------------------------------------------------
namespace Plugins
{
public class Plugin1: IPlugin
{
string GetPluginName()
{
//...
}

void Setup()
{
frmSetup form = new frmSetup();
form.ShowDialog();
}
}

partial class frmSetup : Form
{
public frmSetup()
{
InitializeComponent();
}
}
}

(Project 3: WinApp)
load a plugin:
--------------------------------------------------------------------
namespace WinApp
{
public partial class frmPrincipal: Form
{
public frmPrincipal()
{
InitializeComponent();
Assembly assembly = Assembly.LoadFile("My_Plugin.dll");
Type[] types = assembly.GetTypes(); // This line throws an
error
}
}
}

Error: Unable to load one or more of the requested types. Retrieve the
LoaderExceptions property for more information.

{System.IO.FileNotFoundException: Could not load file or assembly 'API,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its
dependencies. The system cannot find the file specified.
File name: 'API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'

I think that when I run the GetTypes method, the compiler looks in my
plugin assembly and finds that it references my plugin Interface, which
is in another assembly, but it doesn't find it, so it throws this
error.
I tried to solve it by using the GetType method passing the full path
to my plugin class as parameter, but it always returns null...On the
other hand, if I pass the full path for the configuration form class
(which is in the same project, and isn't my objective) it works
fine....

Can someone help me?

Tks

Sep 4 '06 #1
3 2054
auad wrote:
Assembly assembly = Assembly.LoadFile("My_Plugin.dll");

{System.IO.FileNotFoundException: Could not load file or assembly 'API,
It's looking for a file called API.dll instead of My_Plugin.dll. Could
it be that you have renamend the API.dll to My_Plugin.dll after compiling?

I think I remember a similar problem.. when you compile an A.dll, rename
it to B.dll and try to load it dynamically, it will say it cannot find
A.dll. I have never tried to find out why, but it looks like the
assembly name is stored within the assembly.dll and you shouldnt rename it.

I could be all wrong, no time to test this right now, but see if
renaming your my_plugin.dll back to its original name (api.dll) helps.

hth,
Max
Sep 4 '06 #2
sorry Max, I think I wrote something wrong...
When I load the plugin assembly which contains a class that implements
the interface that is defined in API.dll, .Net also looks for the
API.dll because it is referenced in the plugin assembly and then for
some reason it doesn't find it....I've already tried to embed the
API.dll assembly into the plgin assembly, but I got the same error...
Can you help me?

Tks,

Sep 4 '06 #3
I got the solution!

I just referenced the API in the Win App

it worked

tks,

Sep 4 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Rudolf | last post: by
3 posts views Thread by pnp | last post: by
3 posts views Thread by dhnriverside | last post: by
6 posts views Thread by Pete Davis | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.