FIX: OutOfMemoryException Occurs When You Access Non-Fixed Size Safe Arrays in a User-Defined Type

Article translations Article translations
Article ID: 327107 - View products that this article applies to.
This article has been archived. It is offered "as is" and will no longer be updated.
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

On This Page

Symptoms

The following error message occurs when you invoke a method on a Component Object Model (COM) object that returns a user-defined type that contains a Safe array (non-fixed size):
An unhandled exception of type 'System.OutOfMemoryException' occurred in ApplicationName.exe

Additional information: Not enough storage is available to complete this operation.

Cause

This behavior occurs because the .NET Framework cannot marshal a structure field with a Safe array (non-fixed size) type.

Status

This bug was corrected in .NET Framework (2003|1.1).

More information

Steps to Reproduce the Behavior

  1. Create an ActiveX DLL project in Microsoft Visual Basic 6.0. Paste the following code in the default class module, Class1 (Class1.cls):
    Public Type Test
        l As Long
        x() As Integer
    End Type
    
    Public Function Func() As Test
        Dim t As Test
        t.l = 100
        Func = t
    End Function
    					
  2. Make Project1.dll.
  3. Open Microsoft Visual Studio. NET and then create a Windows Application project in Visual Basic .NET.
  4. Add a reference to Project1.dll.
  5. Add a Button control to Form1.
  6. Copy and then paste the following code after the Windows Form Designer generated code region:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim c As New Project1.Class1()
            c.Func()
        End Sub
    					
  7. Compile and then run the application. Click the button.

References

For more information about interop marshaling, visit the following Microsoft Web site:
Interop Marshaling
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconinteropmarshaling.asp

Properties

Article ID: 327107 - Last Review: January 17, 2015 - Revision: 3.0
Applies to
  • Microsoft .NET Framework 1.1
  • Microsoft .NET Framework 1.0
Keywords: 
kbnosurvey kbarchive kbfix kbbug kbcominterop kbpending KB327107

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com