.NET 4.0 Excel Interop Dynamic Collection Issues

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 dropping it and the array, i.e.:

var values = (Array)series.XValues;

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

"Cannot pass an object of type 'System.Object [*]' to enter 'System.Object []'"

.

Any ideas? The following does not work:

  • Casting as dynamic.
  • Dropping him on System.Object[*].
  • Just put the object in for each loop.
  • Attempts to access a value directly using values[1], nor when clicked as dynamic.

However, the values ​​inside the array are displayed in the debugger.

+5
2

.NET , "" . , 1. , SAFEARRAY, 0.

Array.GetValue(). , :

    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;
    }

:

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

. .NET 4.0 , COM-, Office. , . #. # . , (), ().

+5

, , .

.Net 4.0 .

# 4.0

System.Array a = (System.Array)((object)  returnedObject ); // note order of brackets

http://blogs.msdn.com/b/mshneer/archive/2010/06/01/oh-that-mysteriously-broken-visiblesliceritemslist.aspx

+7

All Articles