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



The information in this article 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:

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.

MORE INFORMATION

Steps to Reproduce the Problem

  1. 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:
    1. Start Visual Basic 6.0 to create an ActiveX DLL file.
    2. Rename the Project1 project as InteropTest and Class1 as TestComponent.
    3. 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 = "Roger"
          pi.LastName = "Sims"
          pi.Address = "Hotel California"
          GetPersonalInfo = pi
      End Function
      						
    4. Make InteropTest.dll.
  2. Register InteropTest.dll if it is not already registered.
  3. Run TlbImp.exe on InteropTest.dll to generate InteropTestLib.dll, as follows:
    TlbImp /out:InteropTestLib.dll InteropTest.dll
    					
  4. 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
    					
  5. Save the file as TestClient.vb, and then compile TestClient.vb as follows:
    vbc /debug /t:exe /r:InteropTestLib.dll TestClient.vb
    					
  6. Run TestClient.exe. The System.OutOfMemoryException error is thrown.

Modification Type:MajorLast Reviewed:4/8/2003
Keywords:kbbug kbCOMInterop kbnofix kbpending KB317624