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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:18:19+00:00 2026-05-22T16:18:19+00:00

I am using reflection to handle an assembly loaded at runtime. My problem is

  • 0

I am using reflection to handle an assembly loaded at runtime. My problem is that one of the methods has an output parameter which contains an array of structs.

Here are the declarations from assembly:

public struct WHATEVER
{
}

public class SOMECLASS
{
    public static int methodCall(out WHATEVER[] ppWhateverStructs);
}

And here’s how I tried to execute:

Type tWHATEVER = Assembly.Load("path-to-Assembly").GetType("WHATEVER");
Type tSOMECLASS = Assembly.Load("path-to-Assembly").GetType("SOMECLASS");

Array objStructs = Array.CreateInstance(tWHATEVER, 1);
object[] Params = new object[] { @objStructs };             // tried with and without "@" - same thing

MethodInfo method = tSOMECLASS.GetMethod("methodCall", new Type[] { tWHATEVER.MakeArrayType().MakeByRefType() });
retVal = method.Invoke(null, Params);

when I put ‘Params’ on watch window it shows me that it contains a 1-element array which also contains an N-sized array filled with elements, and objStructs is unchanged. This is correct. My problem is I don’t know how to pick items from sub-array:

object objRestuls = Params[0];

This statement works, shows the items I expect in watch-window, but I don’t know how to iterate and pick them up from object. When I try this:

object [] objRestuls = (object [])Params[0];

The following exception is thrown:

An unhandled exception of type 'System.InvalidCastException' occurred in TestAssembly.dll

Additional information: Unable to cast object of type 'TestAssembly.WHATEVER[]' to type 'System.Object[]'.

Does anyone have a hint on how to read an struct-array encapsulated in an object?

  • 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-22T16:18:20+00:00Added an answer on May 22, 2026 at 4:18 pm

    You could use:

    Array array = (Array) Params[0];
    

    and then iterate over it using the members of Array, or even using foreach (which will box each element).

    The reason it’s currently not working is that an array of value type values isn’t an array of references – so this wouldn’t even compile:

    // Invalid
    object[] array = new int[10];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using reflection class to invoke some methods which are on the some
Using reflection, how can I get all types that implement an interface with C#
Using reflection on Java classes to access all field, methods, and so on: Is
When using reflection it is possible to obtain the call stack (apart from that
How do I define a DynamicMethod for a delegate that has an out -parameter,
I need to invoke a method on a class using reflection. The class contains
I am developing an assembly which has to be installed in the GAC, and
I'm using Autofac to handle dependency injection in my application. However, I have one
I have a problem with reflection. I need to find the type that instantiates
In my 'myClass' class, I am using Reflection.Emit to dynamically write an event handler

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.