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

Ask A Question

Stats

  • Questions 77k
  • Answers 78k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer It is hard to give an answer to this without… May 11, 2026 at 3:36 pm
  • added an answer XPath gives you node-sets, so by definition nodes appear only… May 11, 2026 at 3:36 pm
  • added an answer Interactively, you can display it with help(my_func) Or from code… May 11, 2026 at 3:36 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.