Complicated API issue with dynamic assembly calls

I have an interesting challenge I am wondering if anyone here can give me some direction.

I am writing a Windows Forms application that runs on the web and uses SQL Server to save and pull data.

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

I can create assemblies using my API, copy the file to a folder on the local hard drive, and configure the application to use Reflection to call a specific function from the implemented interface (IDataManipulate.Execute).


Problem:

Since the application will be installed on multiple workstations on the network, it is not possible to copy the plugin DLLs that users will create for each machine.

Solutions I have tried:

Solution 1
Copy the API DLL to a network share.

Problem:
Requires AllowPartiallyTrustedCallersAttribute which requires chanting .Net which I cannot force from my users.

Solution 2 (preferred)
Serialize the dll object, save it to the database, deserialize, and call IDataManipulate.Execute.

Problem:
After deserializing, I try to apply it to the IDataManipulate object, but it returns an error looking for the actual dll file.

Solution 3
Save the dll bytes as byte [] in the database and re-create the dll on the local PC every time the user runs my application.

Problem:
The Dll may have dependencies that I don't know if I can detect.


Any suggestions would be greatly appreciated.

thanks

+2


a source to share


2 answers


I already did "Solution 3". We have saved the DLL files in the database table with the label "last modified". This way you can find out if the local file needs to be updated when the application starts.

You can call Assembly.GetReferencedAssemblies to get a list of assembly dependencies. This assumes the plugin DLL does not use reflection to dynamically load the random assembly, but that should be fine.



Another option is to use the AppDomain.AssemblyResolve event . Instead of loading all plugin DLLs on startup, this event will allow you to load only the DLLs you need.

+1


a source


You can copy them to a network share and then when your application starts or you need to download plugins, you can compare the date with the one you keep locally if it's newer, then copy it locally.



0


a source







All Articles