You receive an "Access violation" error message or a "The memory could not be read" error message when you quit a WinForm program (826220)



The information in this article applies to:

  • Microsoft Office XP Web Components, when used with:
    • Microsoft Visual Studio .NET (2003), Academic Edition
    • Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
    • Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
    • Microsoft Visual Studio .NET (2003), Professional Edition
    • Microsoft Visual Studio .NET (2002), Academic Edition
    • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
    • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
    • Microsoft Visual Studio .NET (2002), Professional Edition
    • Microsoft .NET Framework 1.0
    • Microsoft .NET Framework 1.1

SYMPTOMS

When you quit a Windows Form (WinForm) program that was created in either Microsoft Visual Studio .NET (2002) or Microsoft Visual Studio .NET (2003), you may receive one of the following error messages:
Unhandled exception at 0x77f87e4b (NTDLL.DLL) in [ApplicationName]: 0xC0000005: Access violation reading location 0x00000324.
-or-
The instruction at "0x77f87e4b" referenced memory at "0x00000324". The memory could not be "read". Click on OK to terminate the program.

CAUSE

This problem may occur when both of the following conditions are true:
  • Your display color quality is set to 256 colors.
  • The WinForm program contains a Microsoft Office XP Web Component control.

WORKAROUND

To work around this problem, use one of the following methods.

Method 1: Change Your Display Settings

Change your display settings to run in a mode that is higher than (8-bit) 256 color. To do this, follow these steps:
  1. Click Start, and then click Control Panel.
  2. Click Appearance and Themes.
  3. Click Display.
  4. On the Settings tab, change the color quality to a higher setting (for example, Highest (32 bit)).
  5. Click OK to close the Display Properties dialog box.

Method 2: Run the Managed Code from an Unmanaged Loader

The loader handles process startup and shutdown and can load and unload the Office Web Components and GDIPlus together in an orderly fashion.

For more information, visit the following Microsoft Web site:

Method 3: Unload the Office Web Components Before Unloading GDIPlus

Close all open WinForms, close the Office Web Components, and then close GDIPlus. To do this, add a static Main function to your .NET program, and then add additional code such as the following:

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
 <DllImport("kernel32.dll", EntryPoint:="GetModuleHandle", _
           SetLastError:=True, CharSet:=CharSet.Auto, 
           CallingConvention:=CallingConvention.StdCall)> _
    Public Overloads Shared Function GetModuleHandle(ByVal sLibName As String) As IntPtr
    End Function

    <DllImport("kernel32.dll", EntryPoint:="FreeLibrary", _
        SetLastError:=True, CallingConvention:=CallingConvention.StdCall)> _
    Public Overloads Shared Function FreeLibrary(ByVal hMod As IntPtr) As Integer
    End Function

    <STAThread()> Public Overloads Shared Sub Main()
            Dim hOwcHandle As IntPtr
            System.Windows.Forms.Application.Run(New frmMainForm())
            GC.Collect(2) ' Try to free if all instances were finalized already.
           ' If OWC is still around, then force unload it before exit.
            hOwcHandle = GetModuleHandle("owc10.dll")
            If Not hOwcHandle.Equals(IntPtr.Zero) Then FreeLibrary(hOwcHandle)
 End Sub

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

Modification Type:MinorLast Reviewed:8/23/2006
Keywords:kbvs2002sp1sweep kbBug kberrmsg kbprb KB826220