-1

I have a usercontrol with a webbrowser control on it compiled out to it's own assembly. This control worked in my project prior to breaking it out to its own assembly.

Now the goal of doing this is to late bind to the assembly, instantiate the control, and add it to my tab control on my form.

Dim objAssembly As Reflection.Assembly
objAssembly = Reflection.Assembly.LoadFrom(My.Application.Info.DirectoryPath + "\ppbb.dll")
Me._SelectionDetail1 = objAssembly.CreateInstance("ppbb.SelectionDetail")

When I step through this code it seems to create the object however when I try to set some html to the webbrowser control on the usercontrol it nullrefs.

Do I need to call an initializer on the usercontrol? Can I late bind a user control at all?

Thanks for any help, Tim

thetimmer
  • 186
  • 1
  • 8

1 Answers1

0

When you get a NullReferenceException, it probably means that objAssembly.CreateInstance returned Nothing because it could not find the type you requested (check this using the debugger).

Make sure you specify the type name correct. If your control MyControl is inside a module Test inside a namespace MyLib (just some random names for the sake of an example), you have to use objAssembly.CreateInstance("MyLib.Test+MyControl").

When in doubt, just inspect objAssembly.GetTypes() with the debugger to get a list of all types in that assembly, look for the Type of your control, and inspect the FullName property of that Type.

That's the string you'll have to use so CreateInstance will find the Type.

sloth
  • 99,095
  • 21
  • 171
  • 219