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

  • Home
  • SEARCH
  • 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 143009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:01:39+00:00 2026-05-11T08:01:39+00:00

OK, I’ve been working on something for a while now, using reflection to accomplish

  • 0

OK, I’ve been working on something for a while now, using reflection to accomplish a lot of what I need to do, but I’ve hit a bit of a stumbling block…

I’m trying to use reflection to populate the properties of an array of a child property… not sure that’s clear, so it’s probably best explained in code:

Parent Class:

Public Class parent     Private _child As childObject()     Public Property child As childObject()         Get             Return _child         End Get         Set(ByVal value As child())             _child = value         End Set     End Property End Class 

Child Class:

Public Class childObject     Private _name As String     Public Property name As String         Get             Return _name         End Get         Set(ByVal value As String)             _name = value         End Set     End Property      Private _descr As String     Public Property descr As String         Get             Return _descr         End Get         Set(ByVal value As String)             _descr = value         End Set     End Property End Class 

So, using reflection, I’m trying to set the values of the array of child objects through the parent object…

I’ve tried several methods… the following is pretty much what I’ve got at the moment (I’ve added sample data just to keep things simple):

    Dim Results(1) As String      Results(0) = '1,2'     Results(1) = '2,3'     Dim parent As New parent      Dim child As childObject() = New childObject() {}     Dim PropInfo As PropertyInfo() = child.GetType().GetProperties()     Dim i As Integer = 0     For Each res As String In Results          Dim ResultSet As String() = res.Split(',')         ReDim child(i)          Dim j As Integer = 0         For Each PropItem As PropertyInfo In PropInfo             PropItem.SetValue(child, ResultSet(j), Nothing)             j += 1         Next         i += 1     Next     parent.child = child 

This fails miserably on PropItem.SetValue with ArgumentException: Property set method not found.

Anyone have any ideas?

@Jon :-

Thanks, I think I’ve gotten a little further, by creating individual child objects, and then assigning them to an array… The issue is now trying to get that array assigned to the parent object (using reflection).

It shouldn’t be difficult, but I think the problem comes because I don’t necessarily know the parent/child types. I’m using reflection to determine which parent/child is being passed in. The parent always has only one property, which is an array of the child object. When I try assigning the child array to the parent object, I get a invalid cast exception saying it can’t convert Object[] to .

EDIT: Basically, what I have now is:

Dim PropChildInfo As PropertyInfo() = ResponseObject.GetType().GetProperties() For Each PropItem As PropertyInfo In PropChildInfo     PropItem.SetValue(ResponseObject, ResponseChildren, Nothing) Next 

ResponseObject is an instance of the parent Class, and ResponseChildren is an array of the childObject Class.

This fails with: Object of type ‘System.Object[]’ cannot be converted to type ‘childObject[]’.

  • 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-11T08:01:39+00:00Added an answer on May 11, 2026 at 8:01 am

    Firstly I’d get rid of the array part of the equation – I can’t see how that’s relevant. Try to write code to set the values for a single child.

    Secondly, it seems that you’re relying on the results of GetProperties being in the desired order – you shouldn’t. There’s no guarantee as to what order the properties will be returned in. You should know what order you want based on the string you’re splitting, and fetch the properties by name.

    Thirdly, I suspect the problem is that you’ve got some read-only properties as well as writeable ones. I suggest you whip up a short console app to check this out, logging what properties you’re trying to set before you set it.

    If this doesn’t help, please post a short but complete console app which demonstrates the problem, and I’m sure we’ll be able to fix it.

    EDIT: Okay, if you’re now stuck just on the array part, I suggest you show a short but complete example of that instead. I suspect the problem is that you’ve created an array of the wrong type. You can use Array.CreateInstance to create the right kind of array, which should be valid when you then set the property.

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

Sidebar

Ask A Question

Stats

  • Questions 75k
  • Answers 75k
  • 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 This question has been formulated very loosely and this is… May 11, 2026 at 2:49 pm
  • added an answer iTunes registers itself as a protocol handler for custom itms://… May 11, 2026 at 2:49 pm
  • added an answer An HTA obviously cannot be target of a shell drop… May 11, 2026 at 2:49 pm

Related Questions

OK, I know what you're thinking, "why write a method you do not want
Ok, I asked a question earlier about Flex and ADO.NET Data Services but didn't
Ok, I have been working with Solaris for a 10+ years, and have never
OK, I know there have already been questions about getting started with TDD ..
Ok, I have a strange exception thrown from my code that's been bothering me

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.