Microsoft KB Archive/317624

= BUG: System.OutOfMemoryException Thrown When You Invoke a COM Method That Returns a Structure Containing a String Array =

Article ID: 317624

Article Last Modified on 2/23/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.0

-



This article was previously published under Q317624



SYMPTOMS
When you invoke a method on a Component Object Model (COM) object that returns a structure that contains a string array from a .NET component, a System.OutOfMemoryException error is thrown.



CAUSE
This behavior occurs because the .NET Framework does not support the marshaling of a structure that contains a string array.

For more information about supported data types, browse to the following Microsoft Web site:

Interop Marshaling

http://msdn.microsoft.com/library/default.asp?url=/library/en-us /cpguide/html/cpconinteropmarshaling.asp



RESOLUTION
A fix for this problem is now available. For additional information and to get this fix, click the article number below to view the article in the Microsoft Knowledge Base:

324181 FIX: Marshaling of Fixed Arrays of BSTR Fields in .NET Framework



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Problem
 Create a Microsoft Visual Basic 6.0 COM component with a method that returns a structure containing a string array. To do this, follow these steps:  Start Visual Basic 6.0 to create an ActiveX DLL file. Rename the Project1 project as InteropTest and Class1 as TestComponent .  Add the following code in the TestComponent class: Option Explicit

Public Type PersonalInfo Id As Long FirstName As String LastName As String Address As String Hobbies(10) As String Interests(10) As Variant BankBalance As Currency End Type

Public Function GetPersonalInfo As PersonalInfo Dim pi As PersonalInfo pi.Id = 213 pi.FirstName = &quot;Roger&quot; pi.LastName = &quot;Sims&quot; pi.Address = &quot;Hotel California&quot; GetPersonalInfo = pi End Function  Make InteropTest.dll.</li></ol> </li> Register InteropTest.dll if it is not already registered.</li>  Run TlbImp.exe on InteropTest.dll to generate InteropTestLib.dll, as follows: TlbImp /out:InteropTestLib.dll InteropTest.dll </li>  Start Notepad, and then insert the following code: Class TestClient Shared Sub Main Dim pi As InteropTestLib.PersonalInfo Dim rs As New InteropTestLib.TestComponent pi = rs.GetPersonalInfo End Sub End Class </li>  Save the file as TestClient.vb, and then compile TestClient.vb as follows: vbc /debug /t:exe /r:InteropTestLib.dll TestClient.vb                   </li> Run TestClient.exe. The System.OutOfMemoryException error is thrown.</li></ol>

Keywords: kbbug kbcominterop kbnofix kbpending KB317624

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.