TlbImp System.TypeLoadException: Int32[49285]' has too many dimensions

195 views Asked by At

I have a C++-built tlb that uses SAFEARRAY; I used tlb importer to generate a DLL and build it with C#,I tried different options such as /sysarray and /noclassmembers to generate different signatures for a method:

public void GetList(ref Array HHNums, ref Array PersNums)

and

public void GetList(ref int[] HHNums, ref int[] PersNums)

In both cases I still get an error complaining with System.TypeLoadException that the array has too many dimensions defined. how do fix this error?

My CMD input is "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\tlbimp.exe" /sysarray /out:ADI /noclassmembers /namespace:A.namespace myDTI.tlb

1

There are 1 answers

0
Salah Alshaal On BEST ANSWER

The reason for this was the ref keyword based what I read online, I converted the DLL into .il file; I modified the code by removing the [In] from the parameters of the method:

instance void  GetListWithWeight([In][out] int32[]&  marshal( safearray int32) HHNums,
                                 [In][out] int32[]&  marshal( safearray int32) PerNums,
                                 [In][out] float32[]&  marshal( safearray float32) Wgts) runtime managed internalcall

and it became:

instance void  GetListWithWeight([out] int32[]&  marshal( safearray int32) HHNums,
                                 [out] int32[]&  marshal( safearray int32) PerNums,
                                 [out] float32[]&  marshal( safearray float32) Wgts) runtime managed internalcall

then I packaged the .il into a DLL and ran my program and then it worked fine. I hope this helps someone in the future