472,325 Members | 1,020 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,325 software developers and data experts.

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 2146
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: David Elliott | last post by:
I am trying to load an assembly and execute a method from a class. I have listed 3 parts to the code. 1) The Driver to load and execute 2) The...
3
by: MN | last post by:
Hello all - I was hoping I could appeal to the gurus out there as I've researched this issue and can't seem to get this Flash movie to load at...
2
by: Rudolf | last post by:
Dear NG, I want to create a Plugin System in C# (WinForms). Has anybody experience about this, tips, tricks, or any links. Thank you very much ...
9
by: Ender | last post by:
I have an application that I would like third party developers to be able to create Plug-ins that will be dynamically loaded into our application...
3
by: pnp | last post by:
Hi all, I've created an app that loads some dlls dynamically from the filesystem. All the dlls implement a certain interface so that they can be...
3
by: dhnriverside | last post by:
Hi guys I'm writing a console app in C# for which i want to enable the user to have several "plug-ins". The app has a switch to set the plug-in...
6
by: Pete Davis | last post by:
I'm confused about what precisely the limitations are on loading plugins in separate app domains. In all my previous apps that supported plugins,...
2
by: millevlada | last post by:
Hi all. Here is description of my run-time assembly loading problem: I would like to have winService hosting .Net remoting objects. But, it...
5
by: Anthony P. | last post by:
Hello Everyone, I'm totally lost and I hope someone can help me out or point me to something that can. Here's the deal: I have an application...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.