Stefanos Tses
Stefanos Tses

Reputation: 43

Loading assemblies dynamically‏ AssemblyResolve issue

Note:
This is a continuation of my previous post: Complicated API issue with calling assemblies dynamically‏


I'm writing a .Net windows forms application that runs on a network and uses an SQL Server to save and pull data.

I want to offer a mini "plugin" API, where developers can build their own assemblies and implement a specific interface (IDataManipulate). These assemblies then can be used by my application to call IDataManipulate.Execute().

I've decided to go with solution #3 :

Save the dll bytes as byte[] to the database and recreate the dll at the local PC every time the user starts my application.

So this is what I'm doing:

Everything works; the dlls are loaded and I can call IDataManipulate.Execute() except for this problem:

Problem

When I call IDataManipulate.Execute() from the main assembly, I get an error such as:

"I can't load type xxxx from this assembly".

The type that can't be loaded belongs to one of the referenced assemblies not the main one.

Why this is happening?

Any suggestions?

Upvotes: 0

Views: 842

Answers (2)

Pål Økern
Pål Økern

Reputation: 11

A bit late, but you can also check the PublicKeyToken of the assembly. Three tokens exist for .net, I believe. You can find them by looking in the windows framework folder. This way, you can include assemblies in other folders if you need to.

That said, I would probably require the developer to have them in the same folder as well. In case they decide to include large 3rd party libraries like Infragistics or whatnot. That way they explicitly have to move the assemblies to a folder before importing, making them aware of what they are doing.

Upvotes: 1

SLaks
SLaks

Reputation: 888067

To answer your first question, you can check the referenced assemblies' Location, and only add it to the database if it's in the same folder.

Upvotes: 1

Related Questions