Home All Groups Group Topic Archive Search About

TargetException: Object does not match target type.

Author
4 Apr 2006 9:13 PM
John Wright
I have the following code that sets some public properties in an EXE program
I load using LoadFrom.  I set the property values and all was well.  Then I
changed the loading program to remove a form and clean up some stuff and now
I get the error "Object Does Not Match Targe Type".  What am I doing wrong.
I have included code from both the calling program and the class in the
called program that sets the properties. I can see the

Calling program.

Dim extAssembly As Assembly =
Assembly.LoadFrom("D:\testload\TestLoad\TestLoad\bin\Release\testload.exe")
Dim extForm As Form = extAssembly.CreateInstance("TestLoad.Form1", True)

Dim a As Type = extAssembly.GetType("TestLoad.Login")

TextBox1.Text &= a.ToString & vbCrLf

If a.Name.ToString = "Login" Then

Dim x() As PropertyInfo = a.GetProperties()

TextBox1.Text &= "Properties:" & vbCrLf

For i As Integer = 0 To UBound(x)

Select Case x(i).Name.ToString

Case "UserID"

TextBox1.Text &= "Name: " & x(i).Name.ToString & vbCrLf

x(i).SetValue(extForm, "WrightJW", Nothing)  ----> Produces the Error

Case "UserType"

TextBox1.Text &= "Name: " & x(i).Name.ToString & vbCrLf

x(i).SetValue(extForm, "Admin", Nothing)

Case "Certification"

TextBox1.Text &= "Name: " & x(i).Name.ToString & vbCrLf

x(i).SetValue(extForm, "Certified", Nothing)

End Select

Next

End If

extForm.Name = "TestLoad"

extForm.Text = "TestLoad"

Me.AddOwnedForm(extForm)

extForm.Show()

Called Class
Public Class Login
Private strUserID As String

Private strUserType As String

Private strCertification As String

Public Property UserID() As String

Get

UserID = strUserID

End Get

Set(ByVal value As String)

strUserID = value

End Set

End Property

Public Property UserType() As String

Get

UserType = strUserType

End Get

Set(ByVal value As String)

strUserType = value

End Set

End Property

Public Property Certification() As String

Get

Certification = strCertification

End Get

Set(ByVal value As String)

strCertification = value

End Set

End Property


End Class



John

Author
5 Apr 2006 4:37 PM
John Wright
Nevermind, I found the problem.

john
Show quote
"John Wright" <riley_wri***@notmail.com> wrote in message
news:O4EqZyCWGHA.4848@TK2MSFTNGP03.phx.gbl...
>I have the following code that sets some public properties in an EXE
>program
> I load using LoadFrom.  I set the property values and all was well.  Then
> I
> changed the loading program to remove a form and clean up some stuff and
> now
> I get the error "Object Does Not Match Targe Type".  What am I doing
> wrong.
> I have included code from both the calling program and the class in the
> called program that sets the properties. I can see the
>
> Calling program.
>
> Dim extAssembly As Assembly =
> Assembly.LoadFrom("D:\testload\TestLoad\TestLoad\bin\Release\testload.exe")
> Dim extForm As Form = extAssembly.CreateInstance("TestLoad.Form1", True)
>
> Dim a As Type = extAssembly.GetType("TestLoad.Login")
>
> TextBox1.Text &= a.ToString & vbCrLf
>
> If a.Name.ToString = "Login" Then
>
> Dim x() As PropertyInfo = a.GetProperties()
>
> TextBox1.Text &= "Properties:" & vbCrLf
>
> For i As Integer = 0 To UBound(x)
>
> Select Case x(i).Name.ToString
>
> Case "UserID"
>
> TextBox1.Text &= "Name: " & x(i).Name.ToString & vbCrLf
>
> x(i).SetValue(extForm, "WrightJW", Nothing)  ----> Produces the Error
>
> Case "UserType"
>
> TextBox1.Text &= "Name: " & x(i).Name.ToString & vbCrLf
>
> x(i).SetValue(extForm, "Admin", Nothing)
>
> Case "Certification"
>
> TextBox1.Text &= "Name: " & x(i).Name.ToString & vbCrLf
>
> x(i).SetValue(extForm, "Certified", Nothing)
>
> End Select
>
> Next
>
> End If
>
> extForm.Name = "TestLoad"
>
> extForm.Text = "TestLoad"
>
> Me.AddOwnedForm(extForm)
>
> extForm.Show()
>
> Called Class
> Public Class Login
> Private strUserID As String
>
> Private strUserType As String
>
> Private strCertification As String
>
> Public Property UserID() As String
>
> Get
>
> UserID = strUserID
>
> End Get
>
> Set(ByVal value As String)
>
> strUserID = value
>
> End Set
>
> End Property
>
> Public Property UserType() As String
>
> Get
>
> UserType = strUserType
>
> End Get
>
> Set(ByVal value As String)
>
> strUserType = value
>
> End Set
>
> End Property
>
> Public Property Certification() As String
>
> Get
>
> Certification = strCertification
>
> End Get
>
> Set(ByVal value As String)
>
> strCertification = value
>
> End Set
>
> End Property
>
>
> End Class
>
>
>
> John
>
>
>

AddThis Social Bookmark Button