Some questions about working with dynamic linked dlls  
Author Message
mtgRhox





PostPosted: Visual C# General, Some questions about working with dynamic linked dlls Top

Well, I have some questions.

My executible file (code was written on C# as a Windows Application), while running, should search some directory for *.dll files which have some special properties. That dlls must be written on C# as a UserControl library and they also must implement special class. The questions are: How can I check files or their properties to find out - are that files are dlls of that special type or not and how can I use classes from them ( I want to place that controls on the main Form in executible file)

What should I do or what materials should I read to solve my problem

Thanks for help.



Visual C#13  
 
 
Dah_cn





PostPosted: Visual C# General, Some questions about working with dynamic linked dlls Top

Using Reflector(you can find here: http://www.aisto.com/roeder/dotnet/), you can view the classes and method info from dll files, if you want to add the Windows Form Control from the dll file, you may reference the dll file in Visual Studio and right click the ToolBox Panel, select the "Choose Items" and view select controls in the right assembly file.

 
 
mtgRhox





PostPosted: Visual C# General, Some questions about working with dynamic linked dlls Top

But I want to link dll to program when it is running, not while making source code ...
 
 
xs594





PostPosted: Visual C# General, Some questions about working with dynamic linked dlls Top

Use the reflection API. You can try use Assembly.LoadFile() to attempt to load each dll.

Something like this:

foreach(string Path in ListDLLPaths)
{
try
{
Assembly Asm = Assembly.LoadFile(Path);

Type MyType = Asm.GetType("My.Fully.Qualified.Type");

if(MyType != null)
{
// found type
}
}
catch(Exception ex)
{
// ignore this dll
}
}

Be careful and test your code well - sounds like you're trying to implement plugins. Make sure you understand assembly versioning, etc. or your type may throw exceptions when you try to load and use it.