private static Array CrackSingleDimSafeArray(IntPtr psa) { uint cDims = PropVariantNativeMethods.SafeArrayGetDim(psa); if (cDims != 1L) { throw new ArgumentException(LocalizedMessages.PropVariantMultiDimArray, "psa"); } int lBound = PropVariantNativeMethods.SafeArrayGetLBound(psa, 1U); int uBound = PropVariantNativeMethods.SafeArrayGetUBound(psa, 1U); int n = uBound - lBound + 1; // uBound is inclusive var array = new object[n]; for (int i = lBound, loopTo = uBound; i <= loopTo; i++) { array[i] = PropVariantNativeMethods.SafeArrayGetElement(psa, ref i); } return(array); }