Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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)

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


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.
Posted
Updated 9-Apr-11 17:34pm
v2
Comments
Albin Abel 9-Apr-11 23:14pm    
Check if you are correctly marshaling the data from COM to the .net type.
roberttu_2004 10-Apr-11 1:45am    
Albin,

I used VS2010 add reference to import the Multiframe.exe COM object. I presumed it automatically generate the metadata necessary for COM Interop.
Nish Nishant 10-Apr-11 1:31am    
Which line in your code snippet gives you the error? Is it :

myDs = (Array)mySectionList.D;
roberttu_2004 10-Apr-11 1:43am    
Nishant,

The error is generated at myDs = (Array)mySectionList.D;
Nish Nishant 10-Apr-11 9:40am    
What's the type of mySectionList.D? Can you do a GetType().ToString() on mySectionList.D?

System.Single[*] indicates that the array has a lower bound other than zero. Was this COM object created in classic VB by any chance?

[Edit]
----------

Just noticed that you intentionally create a 1-based array. Is that really required there?
 
Share this answer
 
v3
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900