When I Tried to return an Array
in VFP9 language COM/DLL to my .NET C# project
I receive a System.Object[*]
array and I can not cast to System.Object[]
(Without asterisk).
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Unfortunately, you cannot cast it directly. You can, however, create a new array of type
object[]
and copy the data over. Something like...I had a similar issue. Got an array as a
dynamic
object from an interop assembly, also starting from index one. When I tried to convert this into anArray
object, I got the same error message.Doing as the other answers suggest did not work. For a strange reason, even reading the
Length
property raised the exception.I found this answer, and it worked.
Apparently, if you use C# 4.0, you have to cast the
dynamic
toobject
first, then you can convert it toArray
. In prior versions of .NET you can cast directly.Here is an Explanation why.
Timwi's solution should work fine. You can do something a bit simpler using Linq:
In case you need to recreate a
System.Object[*]
to pass it back to VFP, you can use this overload of theArray.CreateInstance
method:You can use it as follows: