无法将类型为"System.Single [*]"的对象转换为类型为"System.Single []"的对象 [英] Unable to cast object of type 'System.Single[*]' to type 'System.Single[]
问题描述
我正在尝试通过COM连接到Multiframe. COM对象(Multiframe.SectionList mySectionList)返回float类型的一维数组,该数组的第一个元素的索引为1而不是0.
这就是为什么我必须创建第一个索引为1而不是0的数组的原因(请参见CreateArray)
Hi,
I''m trying to connect to Multiframe via COM. The COM object (Multiframe.SectionList mySectionList) returns a single dimension array of type float with the first element of the array having index 1 rather than 0.
This is why I have to create an array with first index being 1 rather than 0 (see CreateArray)
class SectionListArray
{
Array myDs;
public SectPropArray(){}
~SectPropArray(){}
public void Add(ref Multiframe.SectionList mySectionList)
{
int nMem = myMemberList.Count;
CreateArrays(nMem);
FillArrays(mySectionList);
}
private void CreateArrays(int nMem)
{
int[] myLengthsArray = new int[1] { nMem };
int[] myBoundsArray = new int[1] { 1 };
myDs = Array.CreateInstance(typeof(double), myLengthsArray, myBoundsArray);//Depth D
}
private void FillArrays(Multiframe.SectionList mySectionList)
{
myDs = (Array)mySectionList.D;
}
}
当我从VS2008转换为VS2010时,没有警告或错误.确切的代码在VS2008中完美执行.错误消息无法将类型为"System.Single [*]"的对象强制转换为类型为"System.Single [].
我将代码升级到VS2010,以利用.NET 4中的并行编程功能,但在问题得到解决之前,我可能必须还原到VS2008.
When I converted from VS2008 to VS2010 there were no warnings or errors. The exact code executed perfectly in VS2008. The error message is Unable to cast object of type ''System.Single[*]'' to type ''System.Single[].
I upgraded the code to VS2010 to utilise Parallel Programming features in .NET 4 but I may have to revert back to VS2008 until the problem is sorted.
推荐答案
System.Single[*]
表示数组的下界不是零.这个COM对象是不是偶然在经典VB中创建的?
----------
只是注意到您有意创建了一个基于1的数组.据我所知,
System.Single[*]
indicates that the array has a lower bound other than zero. Was this COM object created in classic VB by any chance?
----------
Just noticed that you intentionally create a 1-based array. Is that really required there?
COM对象是在VisualC ++中创建的.该数组返回的是一个基于1的数组,我尝试创建一个基于0的数组,但是在VS2008中不起作用.
The COM object was created in VisualC++ as far I as I''m aware. The array comes back is a 1-based array, I tried creating a 0-based array but that wouldn''t work in VS2008.
这篇关于无法将类型为"System.Single [*]"的对象转换为类型为"System.Single []"的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!