Loading an assembly

  • Thread starter Thread starter Duncan
  • Start date Start date
D

Duncan

Hi Guys & Gals

I'm developing a windows application that is seperated
into logical units. these units are created as user
controls and are loaded at runtime. I'm having a problem
getting the user control to load, I'm using reflections
and createinstance method, but nothing is happening, I
have used this method sometime ago and I cannot remember
the full syntax. this is what I've got so far...

Imports System.Reflection

Private sub LoadModules()
dim Asm as System.Reflection.Assembly
Asm = System.reflection.assembly.loadfrom
("c:\App\bin\IPSMC001.dll")

I thought at this point I create an object and set a
reference to the Asm.createinstance("MC001") like

dim obj as object
obj = Asm.createinstance("IPSMC001.MC001")

but the object is nothing

Any ideas thanks
Duncan
 
Hi,

You could alternatively use

AppDomain.CurrentDomain.CreateInstanceFromAndUnwrap(...)

"Unwrap" is important because you will be getting an object handle instead
of a real object otherwise.
dim obj as object
obj = Asm.createinstance("IPSMC001.MC001")

but the object is nothing

This sounds strange. Not sure about the Assembly's CreateInstance, but the
AppDomain's one should throw an exception when it is unable to instantiate
the requested type.
 
Back
Top