473,549 Members | 2,651 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you start an assembly dynamically with constructors

Here is what I have but it isn't working if someone could point me in
the right direction I would greatly appreciate it.

Try
Dim objAssembly As Reflection.Asse mbly
ds.Tables("Main _Menu").Default View.RowFilter = "Menu_Name =
'" & sender.text & "'"
objAssembly =
objAssembly.Loa dFrom(ds.Tables ("Main_Menu").D efaultView.Item (0).Item("Assem bly"))
Dim typClsX As Type =
objAssembly.Get Type(ds.Tables( "Main_Menu").De faultView.Item( 0).Item("Assemb ly_Type"),
True, True)
objAssembly.Get ReferencedAssem blies()
objAssembly.Get CustomAttribute s(True)
objAssembly.Get EntryAssembly()
Dim cons() As ConstructorInfo
cons = typClsX.GetCons tructors(Bindin gFlags.CreateIn stance
Or BindingFlags.In stance Or BindingFlags.In vokeMethod Or
BindingFlags.Pu blic Or BindingFlags.No nPublic Or
BindingFlags.De claredOnly)
Dim Params() As ParameterInfo = cons(0).GetPara meters()
Dim MyString() As String = {"Test", "Tester"}
Dim Frm As New Form
Frm = Activator.Creat eInstance(typCl sX.BaseType,
BindingFlags.Cr eateInstance Or BindingFlags.In stance Or
BindingFlags.Pu blic Or BindingFlags.De claredOnly)
cons.Initialize ()

<b>Here is where I recieve the error</b>

Activator.Creat eInstance(cons( 0).Invoke(Bindi ngFlags.CreateI nstance Or
BindingFlags.De claredOnly Or BindingFlags.In stance Or
BindingFlags.Pu blic, Nothing, CType(New Object() {New String()
{"TEST"}, New String() {"Tester"}}, Object), Nothing))
Catch ex As Exception
MessageBox.Show (ex.ToString & " " & ex.Message & " " &
Err.Source & " " & Err.Description )
End Try

End Sub
End Class


<b>This is what I am trying to open. I am using general code right now
and will apply it to what I need after I figure it out.</b>

ublic Class Form1
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub SetValues(ByRef label1 As String, ByRef label2 As
String)
Me.Label2.Text = label1
Me.Label3.Text = label2
End Sub

Friend Sub New(ByVal label1 As String, ByVal label2 As String)
MyBase.New()
Me.Label2.Text = Label1
Me.Label3.Text = Label2

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label1 As System.Windows. Forms.Label
Friend WithEvents Label2 As System.Windows. Forms.Label
Friend WithEvents Label3 As System.Windows. Forms.Label
<System.Diagnos tics.DebuggerSt epThrough()Priv ate Sub
InitializeCompo nent()
Me.Label1 = New System.Windows. Forms.Label
Me.Label2 = New System.Windows. Forms.Label
Me.Label3 = New System.Windows. Forms.Label
Me.SuspendLayou t()
'
'Label1
'
Me.Label1.Locat ion = New System.Drawing. Point(0, 0)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing. Size(640, 520)
Me.Label1.TabIn dex = 0
Me.Label1.Text = "This is a test...."
'
'Label2
'
Me.Label2.Locat ion = New System.Drawing. Point(16, 32)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing. Size(224, 24)
Me.Label2.TabIn dex = 1
Me.Label2.Text = "Label2"
'
'Label3
'
Me.Label3.Locat ion = New System.Drawing. Point(16, 88)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing. Size(320, 24)
Me.Label3.TabIn dex = 2
Me.Label3.Text = "Label3"
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(640, 518)
Me.Controls.Add (Me.Label3)
Me.Controls.Add (Me.Label2)
Me.Controls.Add (Me.Label1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

Private Sub Label1_Click(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles Label1.Click

End Sub
End Class

Dec 1 '06 #1
2 1397
Rjjaw,

Using reflection is seldom the right route to the good solution. Can you
tell us what you want to achieve, just a bunch of code does not add much to
our own knowledge. And because that this newsgroup is to learn for everybody
from somebody else (How stupid it sometimes is), it needs to have sense.

Cor
"rjjaw" <jo********@her itagefunds.coms chreef in bericht
news:11******** *************@n 67g2000cwd.goog legroups.com...
Here is what I have but it isn't working if someone could point me in
the right direction I would greatly appreciate it.

Try
Dim objAssembly As Reflection.Asse mbly
ds.Tables("Main _Menu").Default View.RowFilter = "Menu_Name =
'" & sender.text & "'"
objAssembly =
objAssembly.Loa dFrom(ds.Tables ("Main_Menu").D efaultView.Item (0).Item("Assem bly"))
Dim typClsX As Type =
objAssembly.Get Type(ds.Tables( "Main_Menu").De faultView.Item( 0).Item("Assemb ly_Type"),
True, True)
objAssembly.Get ReferencedAssem blies()
objAssembly.Get CustomAttribute s(True)
objAssembly.Get EntryAssembly()
Dim cons() As ConstructorInfo
cons = typClsX.GetCons tructors(Bindin gFlags.CreateIn stance
Or BindingFlags.In stance Or BindingFlags.In vokeMethod Or
BindingFlags.Pu blic Or BindingFlags.No nPublic Or
BindingFlags.De claredOnly)
Dim Params() As ParameterInfo = cons(0).GetPara meters()
Dim MyString() As String = {"Test", "Tester"}
Dim Frm As New Form
Frm = Activator.Creat eInstance(typCl sX.BaseType,
BindingFlags.Cr eateInstance Or BindingFlags.In stance Or
BindingFlags.Pu blic Or BindingFlags.De claredOnly)
cons.Initialize ()

<b>Here is where I recieve the error</b>

Activator.Creat eInstance(cons( 0).Invoke(Bindi ngFlags.CreateI nstance Or
BindingFlags.De claredOnly Or BindingFlags.In stance Or
BindingFlags.Pu blic, Nothing, CType(New Object() {New String()
{"TEST"}, New String() {"Tester"}}, Object), Nothing))
Catch ex As Exception
MessageBox.Show (ex.ToString & " " & ex.Message & " " &
Err.Source & " " & Err.Description )
End Try

End Sub
End Class


<b>This is what I am trying to open. I am using general code right now
and will apply it to what I need after I figure it out.</b>

ublic Class Form1
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub SetValues(ByRef label1 As String, ByRef label2 As
String)
Me.Label2.Text = label1
Me.Label3.Text = label2
End Sub

Friend Sub New(ByVal label1 As String, ByVal label2 As String)
MyBase.New()
Me.Label2.Text = Label1
Me.Label3.Text = Label2

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label1 As System.Windows. Forms.Label
Friend WithEvents Label2 As System.Windows. Forms.Label
Friend WithEvents Label3 As System.Windows. Forms.Label
<System.Diagnos tics.DebuggerSt epThrough()Priv ate Sub
InitializeCompo nent()
Me.Label1 = New System.Windows. Forms.Label
Me.Label2 = New System.Windows. Forms.Label
Me.Label3 = New System.Windows. Forms.Label
Me.SuspendLayou t()
'
'Label1
'
Me.Label1.Locat ion = New System.Drawing. Point(0, 0)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing. Size(640, 520)
Me.Label1.TabIn dex = 0
Me.Label1.Text = "This is a test...."
'
'Label2
'
Me.Label2.Locat ion = New System.Drawing. Point(16, 32)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing. Size(224, 24)
Me.Label2.TabIn dex = 1
Me.Label2.Text = "Label2"
'
'Label3
'
Me.Label3.Locat ion = New System.Drawing. Point(16, 88)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing. Size(320, 24)
Me.Label3.TabIn dex = 2
Me.Label3.Text = "Label3"
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(640, 518)
Me.Controls.Add (Me.Label3)
Me.Controls.Add (Me.Label2)
Me.Controls.Add (Me.Label1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

Private Sub Label1_Click(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles Label1.Click

End Sub
End Class

Dec 2 '06 #2
The application I developed opens slowly because it has to load a lot
of forms that may not be used. What I am attempting to do, and my
overall goal for the complete project is to only load what I need when
it is request such as the forms. I would like to make a dashboard that
each of my departments would use and only load their applications they
need at runtime as well.

Cor Ligthert [MVP] wrote:
Rjjaw,

Using reflection is seldom the right route to the good solution. Can you
tell us what you want to achieve, just a bunch of code does not add much to
our own knowledge. And because that this newsgroup is to learn for everybody
from somebody else (How stupid it sometimes is), it needs to have sense.

Cor
"rjjaw" <jo********@her itagefunds.coms chreef in bericht
news:11******** *************@n 67g2000cwd.goog legroups.com...
Here is what I have but it isn't working if someone could point me in
the right direction I would greatly appreciate it.

Try
Dim objAssembly As Reflection.Asse mbly
ds.Tables("Main _Menu").Default View.RowFilter = "Menu_Name =
'" & sender.text & "'"
objAssembly =
objAssembly.Loa dFrom(ds.Tables ("Main_Menu").D efaultView.Item (0).Item("Assem bly"))
Dim typClsX As Type =
objAssembly.Get Type(ds.Tables( "Main_Menu").De faultView.Item( 0).Item("Assemb ly_Type"),
True, True)
objAssembly.Get ReferencedAssem blies()
objAssembly.Get CustomAttribute s(True)
objAssembly.Get EntryAssembly()
Dim cons() As ConstructorInfo
cons = typClsX.GetCons tructors(Bindin gFlags.CreateIn stance
Or BindingFlags.In stance Or BindingFlags.In vokeMethod Or
BindingFlags.Pu blic Or BindingFlags.No nPublic Or
BindingFlags.De claredOnly)
Dim Params() As ParameterInfo = cons(0).GetPara meters()
Dim MyString() As String = {"Test", "Tester"}
Dim Frm As New Form
Frm = Activator.Creat eInstance(typCl sX.BaseType,
BindingFlags.Cr eateInstance Or BindingFlags.In stance Or
BindingFlags.Pu blic Or BindingFlags.De claredOnly)
cons.Initialize ()

<b>Here is where I recieve the error</b>

Activator.Creat eInstance(cons( 0).Invoke(Bindi ngFlags.CreateI nstance Or
BindingFlags.De claredOnly Or BindingFlags.In stance Or
BindingFlags.Pu blic, Nothing, CType(New Object() {New String()
{"TEST"}, New String() {"Tester"}}, Object), Nothing))
Catch ex As Exception
MessageBox.Show (ex.ToString & " " & ex.Message & " " &
Err.Source & " " & Err.Description )
End Try

End Sub
End Class


<b>This is what I am trying to open. I am using general code right now
and will apply it to what I need after I figure it out.</b>

ublic Class Form1
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub SetValues(ByRef label1 As String, ByRef label2 As
String)
Me.Label2.Text = label1
Me.Label3.Text = label2
End Sub

Friend Sub New(ByVal label1 As String, ByVal label2 As String)
MyBase.New()
Me.Label2.Text = Label1
Me.Label3.Text = Label2

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label1 As System.Windows. Forms.Label
Friend WithEvents Label2 As System.Windows. Forms.Label
Friend WithEvents Label3 As System.Windows. Forms.Label
<System.Diagnos tics.DebuggerSt epThrough()Priv ate Sub
InitializeCompo nent()
Me.Label1 = New System.Windows. Forms.Label
Me.Label2 = New System.Windows. Forms.Label
Me.Label3 = New System.Windows. Forms.Label
Me.SuspendLayou t()
'
'Label1
'
Me.Label1.Locat ion = New System.Drawing. Point(0, 0)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing. Size(640, 520)
Me.Label1.TabIn dex = 0
Me.Label1.Text = "This is a test...."
'
'Label2
'
Me.Label2.Locat ion = New System.Drawing. Point(16, 32)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing. Size(224, 24)
Me.Label2.TabIn dex = 1
Me.Label2.Text = "Label2"
'
'Label3
'
Me.Label3.Locat ion = New System.Drawing. Point(16, 88)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing. Size(320, 24)
Me.Label3.TabIn dex = 2
Me.Label3.Text = "Label3"
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(640, 518)
Me.Controls.Add (Me.Label3)
Me.Controls.Add (Me.Label2)
Me.Controls.Add (Me.Label1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

Private Sub Label1_Click(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles Label1.Click

End Sub
End Class
Dec 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5000
by: Benjamin | last post by:
Hi, I'm currently writing a Web Services that interacts with a database. To allow me to use not just one database provider (for example, I could use MS Access, SQL Server or MySQL), the Web Service dynamically loads up an assembly that implements an Interface I called IDatabase. To load the assembly and create an object, I wrote this...
7
3155
by: Kyle M. Burns | last post by:
I have an application where I needed to refactor to a base class using the template method pattern in order to avoid duplication of code between two objects that needed to fulfill the same obligation in a different manner. The classes are publicly visible because the application will be used by other applications. What I would like to do is...
4
1484
by: Andrew Backer | last post by:
Hello, I am having a problem creating a class dynamically. The class I have is a base class of another, and the parent class has the constructor (which takes one argument). The base class (Class1, below) does not have any constructors. I am using code like this to create it, and it's blowing up : Dim res As Object =...
2
1766
by: Mark Raishbrook | last post by:
A client of mine is getting a NullReferenceException when starting up a small app I've written. I've traced the cause to an unregistered DLL the app references, so the error itself is not the problem. What I would like to do is trap it, but I'm not sure where I should do this. Here's an excerpt from the exception text: ...
0
815
by: Ron M. Newman | last post by:
Hi, I have a custom string collection editor for my property grid. when I set the property.customEditor, I found to my amazement that you can't instantiate a new object from an assembly that's loaded dynamically. Test code: CollectionEditor editor = (CollectionEditor)myAssembly.CreateInstance("xxx.xxx.xxx.MyStringCollectionEditor"); //...
3
3985
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user selects? thanks...
2
3093
by: Smithers | last post by:
Using 3.5, I am stuck in attempting to: 1. Dynamically load an assembly 2. Instantiate a class from that assembly (the client code is in a different namespace than the namespace of the dynamically loaded assembly) so far so good (per my code below)... but here is where I'm getting hung up: 3. Call methods of that type (see comments in my...
2
2040
by: Jeff | last post by:
Hi I'm trying to achieve a scenario where I have c# files that are compiled dynamically, the assemblies are then loaded in a different AppDomain, I call a simple method from the object, and then unload the AppDomain to release the lock on the assemly files (so to I can compile the code again if it has been modified). However, I've...
8
3221
by: puzzlecracker | last post by:
is there a way to create a library (assembly/dll) where I can only export few class? I don't want client to use or know about other internal classes in the assembly. Thanks
0
7532
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7730
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7975
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7492
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6059
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5101
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3510
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1069
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.