C# DLL-plugin references


T

Tim

Hi,

I've been struggling for a while trying to run plugins in C#, which
have external references.
The plugins load, and I can invoke methods through reflection until
the method uses some code defined in an external assembly.

The error returned is in all cases:

"Could not load file or assembly 'MyAssName, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies. The
system cannot find the file specified.".

The only sollution I could find so far, is to manually add references
to these assemblies in the host project, which defies the purpose of
the plugin-system.

Is there a way, without using the GAC, to reference these assemblies
at runtime?

Thanks in advance,
Tim
 
Ad

Advertisements

D

Daniel Bass

Tim

Ensure:
1. the assemblies you're wanting to reference are in the same folder as the
executing assembly when calling Assembly.LoadFrom(...DLL name...)
2. you pass in the fully qualified object name (prefixed with namspace
information) when calling GetType on your assembly.

To check what object types are available in a DLL, you can call GetTypes on
the Assembly, which returns an array of available types.

Good luck!
Dan.
 
B

Ben Voigt [C++ MVP]

Tim said:
Hi,

I've been struggling for a while trying to run plugins in C#, which
have external references.
The plugins load, and I can invoke methods through reflection until
the method uses some code defined in an external assembly.

The error returned is in all cases:

"Could not load file or assembly 'MyAssName, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies. The
system cannot find the file specified.".

The only sollution I could find so far, is to manually add references
to these assemblies in the host project, which defies the purpose of
the plugin-system.

Is there a way, without using the GAC, to reference these assemblies
at runtime?

The way I do it, is after I load each assembly, iterate through its
dependencies, and for each assembly not yet loaded, try to load it from the
plugin directory as well.
 
Ad

Advertisements

T

Tim

Tim

Ensure:
1. the assemblies you're wanting to reference are in the same folder as the
executing assembly when calling Assembly.LoadFrom(...DLL name...)
2. you pass in the fully qualified object name (prefixed with namspace
information) when calling GetType on your assembly.

To check what object types are available in a DLL, you can call GetTypes on
the Assembly, which returns an array of available types.

Good luck!
Dan.

Thanks for your reply, Daniel.
This allowed me to run the plugin properly!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top