About Creating Objects Dynamically (Cont')

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

Thanks Chris :

However, during run time, it show error message

"File / component cannot find "
during run in
Dim asm As [Assembly] =
AppDomain.CurrentDomain.Load("D:\vb7Project\dynamicCall\prj01\prj01\bin\prj0
1.dll")

or
Dim asm As [Assembly] = AppDomain.CurrentDomain.Load("prj01.dll")

how can fix it


Thanks
Ok Thank :

However How to do it as dynamic ?
I mean , the reference only create on runtime , rather than Predefine.

In order to dynamically create an instance of the class, you must load the
assembly. Then you can call the GetType method to get the type you're
looking for and create and instance. This code is untested but should give
you some clues. (Note the square brackets around the word Assembly. This
is required since Assembly is a keyword in VB)

Imports System.Reflection

'Dynamically load the .dll
Dim assy As String = "NameOfAssembly.dll"
Dim asm As [Assembly] = AppDomain.CurrentDomain.Load(assy)
Dim ty As Type = asm.GetType("TypeName")
Dim obj As Object = Activator.CreateInstance(t)

Hope this helps you.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
Thanks Chris :

However, during run time, it show error message

Try something like this:


Imports System.Reflection

Dim asm As [Assembly] = [Assembly].LoadFrom(AssyFileName)
Dim ty As Type = asm.GetType("TypeName")
Dim obj As Object = Activator.CreateInstance(t)


--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
Thanks

I get it


Many Thanks


Chris Dunaway said:
Thanks Chris :

However, during run time, it show error message

Try something like this:


Imports System.Reflection

Dim asm As [Assembly] = [Assembly].LoadFrom(AssyFileName)
Dim ty As Type = asm.GetType("TypeName")
Dim obj As Object = Activator.CreateInstance(t)


--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
Back
Top