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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:23:21+00:00 2026-05-19T14:23:21+00:00

In Excel you can return a dynamic array System.Object[*] , from a series object

  • 0

In Excel you can return a dynamic array System.Object[*], from a series object using XValues. In .NET 3.5 you can access the elements in this object by casting it to and array, i.e.:

var values = (Array)series.XValues;

In .NET 4.0, this no longer works, and the message

“Unable to cast object of type ‘System.Object[*]’ to type ‘System.Object[]'”

is given.

Any ideas? The following doesn’t work:

  • Casting it as dynamic.
  • Casting it to a System.Object[*].
  • Just placing the object in a for each loop.
  • Trying to access the value directly using values[1], neither when cast as a dynamic.

The values inside the array do show up in the debugger however.

  • 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-19T14:23:22+00:00Added an answer on May 19, 2026 at 2:23 pm

    There are two distinct kind of arrays in .NET, a one dimensional ‘vector’ and multidimensional arrays. You got the latter back, a multidimensional array with a rank of 1. This will happen if the unmanaged code has returned a SAFEARRAY whose lower-bound isn’t 0.

    You can read the content of the array with Array.GetValue(). Or convert it, like this:

        private static object[] ConvertArray(Array arr) {
            int lb = arr.GetLowerBound(0);
            var ret = new object[arr.GetUpperBound(0) - lb + 1];
            for (int ix = 0; ix < ret.Length; ++ix) {
                ret[ix] = arr.GetValue(ix + lb);
            }
            return ret;
        }
    

    Test:

        var native = Array.CreateInstance(typeof(object), new int[] { 42 }, new int[] { 1 });
        var dotnet = ConvertArray(native);
    

    NOTE: you may have a problem in .NET 4.0 and up when you some COM type libraries, Office in particular. The property or method may return a variant that contains an array. Ends up as dynamic in your C# program. The C# compiler does not generate the proper binder code in that case. Work around that by casting first to (object), then to (Array).

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

Sidebar

Related Questions

I'm using Microsoft.Office.Interop.Excel, and I can't find a way to return the selected rows.
Can excel web services be used to create pivot grids from asp.net or silverlight?
What function can I use in Excel VBA to slice an array?
How can I create the Infinite symbol in an excel sheet programmatically? Preferably from
I'm trying to read from excel file with oleDB provider using C#: using (var
I have an working Excel file, with file I can send data extracted from
I can use properties of an Excel Worksheet to tell if the worksheet is
How can I capture the event in Excel when a user clicks on a
How can I automatically execute an Excel macro each time a value in a
Can you use calculated fields in Excel 2007 pivot tables when the data source

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.