Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 76367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:39:44+00:00 2026-05-10T20:39:44+00:00

I’m digging into Reflection for the first time and I’m truely stuck. I’ve googled

  • 0

I’m digging into Reflection for the first time and I’m truely stuck. I’ve googled everything I can think of. I’m 90% where I wanna be now.

I’m trying to return the value of a Property in a custom class through Reflection.

Here’s my class declaration:

Public Class Class2     Private newPropertyValue2 As String      Public Property NewProperty2() As String         Get             Return newPropertyValue2         End Get         Set(ByVal value As String)             newPropertyValue2 = value         End Set     End Property    End Class 

The class I’ve written to look at the class through reflection looks like this:

Public Class ObjectCompare     Private _OriginalObject As PropertyInfo()      Public Property OriginalObject() As PropertyInfo()         Get             Return _OriginalObject         End Get         Set(ByVal value As PropertyInfo())             _OriginalObject = value         End Set     End Property      Public Sub CompareObjects()         Dim property_value As Object          For i As Integer = 0 To OriginalObject.Length - 1             If OriginalObject(i).GetIndexParameters().Length = 0 Then                 Dim propInfo As PropertyInfo = OriginalObject(i)                  Try                     property_value = propInfo.GetValue(Me, Nothing)                 Catch ex As TargetException                 End Try                End If         Next     End Sub End Class 

I put a breakpoint on the property_value = propInfo.GetValue(Me, Nothing) line to see what the result is.

Here’s how I call my code:

Dim test As New Class2 test.NewProperty2 = '2'  Dim go As New ObjectCompare Dim propInf As PropertyInfo() propInf = test.GetType.GetProperties()  go.OriginalObject = propInf  go.CompareObjects() 

Through reflection I can see the PropertyName and Type, all I need is the value of the Property! Now when I get to the breakpoint, I get a TargetException and the error message says ‘Object does not match target type.’ Its now 1AM in the morning and I’m wrecked, any help right now would be appreciated. I’ve searched MSDN and Google to death and then on last time for fun 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T20:39:45+00:00Added an answer on May 10, 2026 at 8:39 pm

    Me refers to the ObjectCompare object, which is different than the class from which the PropertyInfo objects were derived (Class2). You need to also pass in an object of the type from which you retrieved the PropertyInfo objects.

    Public Sub CompareObjects(ByVal It as Object)     Dim property_value As Object      For i As Integer = 0 To OriginalObject.Length - 1         If OriginalObject(i).GetIndexParameters().Length = 0 Then             Dim propInfo As PropertyInfo = OriginalObject(i)              Try                 property_value = propInfo.GetValue(It, Nothing)             Catch ex As TargetException             End Try            End If     Next End Sub  go.CompareObjects(test) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.