Activator.CreateInstance Problems

H

Huw

I have written a small procedure that opens a dialog that
I pass it.

Sub MyOpen(txtForm as string)

Dim frm As Object
Dim frmType As Type
frmType = Type.GetType(txtForm)
frm = Activator.CreateInstance(frmType)
frmType.InvokeMember("ShowDialog",
BindingFlags.InvokeMethod, Nothing, frm, Nothing)

End Sub

This works fine when I pass it form names that exist in
the current .exe file e.g. MyOpen("MyApp.MyForm")

However what I really want to do is open forms that are
contained in a sperate windows .dll file i.e. MyOpen
("MyDll.MyForm"), but it does not seem to work... Will it
work if I supply the full public token id as the string?
If so how do I obtain the full public token id of a form
in a seperate .dll file?

Thanks in advance
 
V

Vijayakrishna Pondala

Use the static method Assembly.Load(assemblyDisplayName) to load the
assembly that contains the form. Using that assembly reference, make a call
to GetType().
Sub MyOpen(txtForm as string)

--->
Dim asmbly = Assembly.Load("AssemblyDisplayName")
frmType = asmbly.GetType(txtForm)
--->

End Sub

Thanks,
Vijaya Krishna P.
 
J

Jay B. Harlow [MVP - Outlook]

Huw,
In addition to Vijaya Krishna P's comments.

You can include the assemble name in the string you pass to Type.GetType.

MyOpen("MyDll.MyForm, MyDll")

Which presumes that you named the assembly & namespace where the MyForm is
the same name (which is the default).

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top