Click here to Skip to main content
16,012,061 members
Home / Discussions / C#
   

C#

 
PinnedHOW TO ANSWER A QUESTION PinPopular
Chris Maunder12-Jul-09 22:36
cofounderChris Maunder12-Jul-09 22:36 
PinnedHow to get an answer to your question Pin
Chris Maunder10-Nov-05 16:31
cofounderChris Maunder10-Nov-05 16:31 
QuestionHow to use functions of a dll in another dll "on the fly" Pin
AtaChris28-Sep-24 1:56
AtaChris28-Sep-24 1:56 
AnswerRe: How to use functions of a dll in another dll "on the fly" Pin
Richard MacCutchan28-Sep-24 3:21
mveRichard MacCutchan28-Sep-24 3:21 
GeneralRe: How to use functions of a dll in another dll "on the fly" Pin
AtaChris28-Sep-24 3:40
AtaChris28-Sep-24 3:40 
GeneralRe: How to use functions of a dll in another dll "on the fly" Pin
Richard MacCutchan28-Sep-24 3:42
mveRichard MacCutchan28-Sep-24 3:42 
AnswerRe: How to use functions of a dll in another dll "on the fly" Pin
Luc Pattyn28-Sep-24 8:00
sitebuilderLuc Pattyn28-Sep-24 8:00 
Hi,

I have an appliction that loads extensions from a specific folder; each extension is a class that derives from a base class DTF_ComponentBase, which happens to be a UserControl as all extensions need a very similar dialog window. Each extension is built into a separate DLL file. This is the heart of the code that loads those DLL files:

C#
private readonly List<DTF_ComponentBase> DTFlist=new List<DTF_ComponentBase>();
    ...
// scan DTFAddins folder
DTFlist.Clear();
string folder = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
//folder += @"\DTFAddins";
log("folder=" + folder);
Directory.CreateDirectory(folder);
string[] dlls = Directory.GetFiles(folder, "*.dll");
Exception firstException = null;
List<string> errors = new List<string>();
foreach (string dll in dlls) {
    if (dll.Contains("LPplatformDLL.dll")) continue;
    try {
        log("File: " + dll);
        if (dll.Contains("DTF_ComponentBase.dll")) continue;
        Assembly asm2 = Assembly.LoadFile(dll);
        Type[] types = asm2.GetTypes();
        // find all classes implementing DTF_ComponentBase
        foreach (Type type in types) {
            //log("    Type=" + type.FullName);
            if (type.IsSubclassOf(typeof(UserControl))) {
                UserControl uc = (UserControl)Activator.CreateInstance(type);
                if (uc is DTF_ComponentBase comp && !comp.Skip) {
                    DTFlist.Add(comp);
                    break;
                }
            }
        }
    } catch (Exception exc) {
        if (firstException == null) firstException = exc;
        errors.Add("Error loading "+dll+"; "+exc.Message);
    }
}


At the end DTFlist contains all the extensions that were found and instantiated; a foreach loop can then be used to issue commands such as Start, Stop, ... whatever the base class provides.

Hope this helps.

Smile | :)
Luc Pattyn [My Articles]
The Windows 11 taskbar is a disgrace; a third-party add-on is needed to reverse the deterioration. I decline such a downgrade.


modified 23hrs ago.

AnswerRe: How to use functions of a dll in another dll "on the fly" Pin
jschell1 hr 56mins ago
jschell1 hr 56mins ago 
QuestionInterface with a default implementation Pin
Richard Andrew x6427-Sep-24 17:42
professionalRichard Andrew x6427-Sep-24 17:42 
AnswerRe: Interface with a default implementation Pin
Luc Pattyn28-Sep-24 1:14
sitebuilderLuc Pattyn28-Sep-24 1:14 
GeneralRe: Interface with a default implementation Pin
Richard Andrew x6423hrs 12mins ago
professionalRichard Andrew x6423hrs 12mins ago 
GeneralRe: Interface with a default implementation Pin
Luc Pattyn22hrs 58mins ago
sitebuilderLuc Pattyn22hrs 58mins ago 
GeneralRe: Interface with a default implementation Pin
Richard Andrew x6422hrs 14mins ago
professionalRichard Andrew x6422hrs 14mins ago 
GeneralRe: Interface with a default implementation Pin
Luc Pattyn22hrs 12mins ago
sitebuilderLuc Pattyn22hrs 12mins ago 
GeneralRe: Interface with a default implementation Pin
Richard Andrew x6422hrs 3mins ago
professionalRichard Andrew x6422hrs 3mins ago 
GeneralRe: Interface with a default implementation Pin
Luc Pattyn21hrs 58mins ago
sitebuilderLuc Pattyn21hrs 58mins ago 
AnswerRe: Interface with a default implementation Pin
jschell1 hr 51mins ago
jschell1 hr 51mins ago 
QuestionWhy doesn't Console.Writeline write to the debugger in .NET 8? Pin
Richard Andrew x6426-Sep-24 4:07
professionalRichard Andrew x6426-Sep-24 4:07 
AnswerRe: Why doesn't Console.Writeline write to the debugger in .NET 8? Pin
Ravi Bhavnani26-Sep-24 4:44
professionalRavi Bhavnani26-Sep-24 4:44 
GeneralRe: Why doesn't Console.Writeline write to the debugger in .NET 8? Pin
Richard Andrew x6426-Sep-24 5:33
professionalRichard Andrew x6426-Sep-24 5:33 
QuestionGame Pin
Homam Obedo25-Sep-24 10:45
Homam Obedo25-Sep-24 10:45 
AnswerRe: Game Pin
jeron125-Sep-24 10:54
jeron125-Sep-24 10:54 
AnswerRe: Game Pin
OriginalGriff25-Sep-24 19:42
mveOriginalGriff25-Sep-24 19:42 
QuestionHow do I check for existance or clear the contents of a SharePoint List from C# code? Pin
Xarzu19-Sep-24 7:58
Xarzu19-Sep-24 7:58 
AnswerRe: How do I check for existance or clear the contents of a SharePoint List from C# code? Pin
charles henington20-Sep-24 9:26
charles henington20-Sep-24 9:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.