System.Activator.CreateInstance

G

Guy

im running some code to instantiate a form, based on the
name selected at runtime.

Im using System.Activator.CreateInstance to load a form
by its fully typed name, here is the code....

string fName = "frmToLoad";
Form myForm;

myForm = (Form)System.Activator.CreateInstance
(Type.GetType("HCS.SkillsRegister.Projects.UI." + fName));

this all works fine providing the form/type i am loading
is in the same assembly as the one this code piece is in
(the main executing assembly). I have an assembly that
uses the exact same namespace as the one the code
executes from(its a referenced dll), but yet i always get
a null reference exception when i try to load one of the
types from the referenced assembly. Even when i
instantiate an object from the referenced assembly first
(to preload the assembly) it still doesnt work.

The full type name is also correct

What am i missing here?
 
S

Selvin

<ciach>
did you try
Assembly.LoadFrom("c:\blable.dll").CreateInstance("ble");
??

pozdrawiam

Przemek Sulikowski
 
J

Jeffrey Tan[MSFT]

Hi Guy,

You should get the loaded assembly's reference, then you can use reflection
on this assembly reference to create what you want.

Best regards
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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