PC Review


Reply
Thread Tools Rate Thread

TargetException: Object does not match target type.

 
 
John Wright
Guest
Posts: n/a
 
      4th Apr 2006
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
 
 
 
 
John Wright
Guest
Posts: n/a
 
      5th Apr 2006
Nevermind, I found the problem.

john
"John Wright" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Object does not match target type. rn5a@rediffmail.com Microsoft ASP .NET 4 21st Feb 2007 02:57 PM
Erratic error System.Reflection.TargetException: Object does not match target type. Joshua Ellul Microsoft Dot NET Framework 1 28th Sep 2006 02:04 PM
object does not match target type reflection Error John Wright Microsoft VB .NET 0 4th Apr 2006 08:07 PM
"gridview Object does not match target type" error during binding collection of different type object gui.besse@gmail.com Microsoft ASP .NET 0 9th Mar 2006 11:28 AM
Object does not match target type Joshua Ellul Microsoft Dot NET Framework 0 14th Mar 2005 11:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:33 PM.