Displaying a form from a dynamically loaded DLL

后端 未结 4 639
情深已故
情深已故 2020-12-29 11:14

This is an extension of a question I previously asked here.

Long story short, I dynamically load a DLL and make a type out of it with the following code:

4条回答
  •  攒了一身酷
    2020-12-29 11:41

    I would go with:

    Assembly assembly = Assembly.LoadFile("C:\\test.dll");
    Type type = assembly.GetType("test.dllTest");
    object obj = Activator.CreateInstance(type);
    Form form = obj as Form;
    if (form != null)
        form.Show(); //or ShowDilaog() whichever is needed
    

    Other error checking/handling should be added; however at the very least I would ensure the conversion works.

提交回复
热议问题