Hi Yogesh, I will try to answer your question, but this is just a speculation.
SafeArray descriptor contains a field called fFeatures. Among others, this field describes the type of the array element. It looks that initially the only supported arrays were arrays of BSTR, Variant, IUnknown* and IDispatch*. When you use SafeArrayCreateVector for these arrays everything works fine. Afterwards, other array types were added. This works by setting fFeatures field value to FADF_HAVEVARTYPE and keeping VT tag at the negative offset 4. To support this, SafeArrayCreateVectorEx was created. If you still use "old" SafeArrayCreateVector for these new types, the array will be created, but no type information will be included in SafeArray descriptor. Now, back to your question. If you wrap SafeArray in Variant, you have the type information both in Variant (vt field) and SafeArray descriptor (fFeatures field). I suppose that VB gets type information from the Variant, so it works even if SafeArray descriptor does not contain the right type. Unfortunately, .NET Interop does the contrary (or maybe checks both ?) Have fun with .NET George -----Original Message----- From: Yogesh Shetty [mailto:[EMAIL PROTECTED]] Sent: Thursday, June 20, 2002 2:43 AM To: [EMAIL PROTECTED] Subject: [DOTNET] SafeArrayTypeMisMatchException I have posted this article in this list but not got an reply... I have got a solution from Advance-dot net... This is FYI.. And subsequent use... -----Original Message----- From: Yogesh [ <mailto:[EMAIL PROTECTED]> mailto:[EMAIL PROTECTED]] On Behalf Of Yogesh S Sent: Thursday, June 20, 2002 12:37 PM Subject: SafeArrayTypeMisMatchException Hi, Extremely sorry...thx a lot.. It worked... But can u explain the reason behind such multi-faceted behaviour ...When the same compoennt is called thru VB it works but when called thru .NET it fails...That means I have to go and replace SafeArrayCreateVector with SafeArrayCreateVectorEx every where it is referenced in my component.. -----Original Message----- From: Moderated discussion of advanced .NET topics. [ <mailto:[EMAIL PROTECTED]> mailto:[EMAIL PROTECTED]] On Behalf Of George Hendel Sent: Wednesday, June 19, 2002 8:01 PM To: <mailto:[EMAIL PROTECTED]> [EMAIL PROTECTED] Subject: Re: [ADVANCED-DOTNET] SafeArrayTypeMisMatchException Instead of lpSafeByteArray = SafeArrayCreateVector (VT_UI1, 0, sizeof (MessageHeader) + (lnAccessListCnt * sizeof (tagUserAccessControlList))); try lpSafeByteArray = SafeArrayCreateVectorEx (VT_UI1, 0, sizeof (MessageHeader) + (lnAccessListCnt * sizeof (tagUserAccessControlList)), 0); George -----Original Message----- From: Yogesh Shetty [ <mailto:[EMAIL PROTECTED]> mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 19, 2002 12:13 AM To: <mailto:[EMAIL PROTECTED]> [EMAIL PROTECTED] Subject: [ADVANCED-DOTNET] SafeArrayTypeMisMatchException I am facing a problem while invoking a com ( developed in VC++) method from .NET, I have enclosed below both VC++ & .NET Code, when i invoke this component from VB 6.0 it works fine and both the out parameter pvarAccessList & pvarErrorMsg gets filled and returned properly. pvarAccessList returns a byte array and pvarErroMsg returns a string ... But when invoked thru .NET it gives error msg "SafeArrayTypeMisMatchException Specified Array was not of expected type"... My head is getting sore from too much debugging... can any one shed some light on this... ................................ ................................ Regards Yogesh Shetty Team COE Financial Technologies (India) Ltd. URL: < <http://www.ftindia.com> http://www.ftindia.com> <http://www.ftindia.com> www.ftindia.com mailto : < <mailto:[EMAIL PROTECTED]> mailto:[EMAIL PROTECTED]> <mailto:[EMAIL PROTECTED]> [EMAIL PROTECTED] contact : +91 22 6164145 You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or subscribe to other DevelopMentor lists at <http://discuss.develop.com> http://discuss.develop.com. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.