473,396 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 2205
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 Interface 3) The assembly I have a valid referece...
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 all. Below is my javascript code that I use to...
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 The DotNetJunkie
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 to extend functionality. I have utilized the...
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 easily manipulated from the main app. The dlls work...
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 to use, and at runtime the required dll is loaded...
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, I've loaded them into the same domain as the app,...
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 should work in sort of pluginable way, so during...
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 that will implement a 'plugin' archetecture of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.