PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Framework TargetException: Object does not match target type.

Reply

TargetException: Object does not match target type.

 
Thread Tools Rate Thread
Old 04-04-2006, 11:13 PM   #1
John Wright
Guest
 
Posts: n/a
Default TargetException: Object does not match target type.


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



  Reply With Quote
Old 05-04-2006, 06:37 PM   #2
John Wright
Guest
 
Posts: n/a
Default Re: TargetException: Object does not match target type.

Nevermind, I found the problem.

john
"John Wright" <riley_wright@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
>
>
>



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off