Dynamic .dll loading - .NET

Deeko

Lifer
Jun 16, 2000
30,213
12
81
I'm trying to find out how, in .NET/C#, to dynamically load a library. Basically, I want to be able to include or remove a .dll file from my product without recompiling. What's the simplest way to do this?
 

Apathetic

Platinum Member
Dec 23, 2002
2,587
6
81
I think what you're looking for is in the "reflection" library of .NET.

Here's a cheesy console app I threw together. It makes in instance of a class and calls methods from it given only the name and path of the DLL.



Dave
 

Deeko

Lifer
Jun 16, 2000
30,213
12
81
I think that's what I need, but I can't get it to work right.

When I try to call GetTypes(), I get an exception, it says not all types can be loaded. What could be causing this? The assmebly is loading, I can get its name and version number and all that...

thanks
 

itachi

Senior member
Aug 17, 2004
390
0
0
assemblies of that sort are an attribute of the .net framework.. as is the GetTypes method. if you want to access the native binary from managed code.. you have to export the symbol when you're compiling the dll and import the symbol in your c# application (along with marshalling and unmarshalling the types).

// in exp.c
extern "C" void __declspec(dllexport) get_message(char *);

// in imp.cs
[DllImport(__DLL_NAME__[, CharSet=__CHARSET__[, EntryPoint=__SYMBOLNAME__[, CallingConvention=__CALLCONV__]]])]
extern void get_message([In, Out] String);