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 7069475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:27:00+00:00 2026-05-28T05:27:00+00:00

I have an object, RenderComponent , that has a property named Model that is

  • 0

I have an object, RenderComponent, that has a property named Model that is of type StaticModel. When I get the PropertyInfo of my RenderComponent and then call GetValue() on it, it is giving me a TargetException, saying “Object does not match target type.”

I’ll write a small sample of code to give you the gist of what is failing. Here’s the hierarchy:

public class RenderComponent
{
    StaticModel Model;
}

public class StaticModel
{

}

And I’m essentially doing this:

RenderComponent renderComponent = new RenderComponent();
PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);

foreach (PropertyInfo info in props)
{
    // I get the exception here
    Object value = info.GetValue(renderComponent, null);
}

My program is of course much more complicated, but I still don’t see how it could be failing. I must be missing something simple.

I get the exception on this line:

info.GetValue(obj, null)

Where info is the PropertyInfo of StaticModel, and obj is an instantiated RenderComponent. When I stop at this exception and do a watch on obj, I can actual step through the hierarchy until I get to my StaticModel value, and it exists and has the data I would expect.

I’m sure if I took the small code sample I posted in this thread it would work fine, so it has to be something with how I’m calling it within my engine, I just don’t see how GetValue can fail when obj clearly has that value within it.

Here’s a screenshot of me debugging ‘obj’ and finding the StaticModel:
enter image description here

And here’s the error I get:
enter image description here

And here you can see the values of obj and info, as proof that my object instance I’m passing is a RenderComponent, and the PropertyInfo I’m calling GetValue on is a Static Model (which is a member of RenderComponent, as you can see in the first image:
enter image description here

  • 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. Editorial Team
    Editorial Team
    2026-05-28T05:27:00+00:00Added an answer on May 28, 2026 at 5:27 am

    sos00’s comment from the original question was the correct answer to this question. His comment was:

    Why does obj (in last Watch screenshot) has Key & Value? isn’t supposed to be a RenderComponent ? I think you are passing a KeyValuePair instead of a RenderComponent instance

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have object A which in turn has a property of type Object B
I have two tables: object that has object_id column and avalues that have object_id
Say I have Object A which has a member of type Object B.. and
I think I read somewhere that some modules only have object oriented interfaces (
I have an object that is mapped to a cookie as a serialized base-64
I have an object in a multi-threaded environment that maintains a collection of information,
I have an object of the type System.Drawing.Image and want to make every pixel
I have an object that implements IDisposable that is registered with the Windsor Container
I have object Country, which has Areas. Areas has Provinces. Provinces has Cities, and
suppose i have object has key 'dlist0' with attribute 'row_id' the i can access

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.