Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8679575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:00:24+00:00 2026-06-12T21:00:24+00:00

The application itself is 2000 lines long so it wouldn’t make sense to paste

  • 0

The application itself is 2000 lines long so it wouldn’t make sense to paste the code here, especially since the exception that one of the users received does not give any hints as to what part of my code is causing the problem.

The app, by the way, is just a Windows Form with a datagridview that typically displays no more than a few hundred rows of data, and some other controls. Before it crashed, it was loading the cells of each row of the datagridview extremely slowly. (But no other user has experienced the same problem.)

The exception text is below. Can someone please review it and tell me if it’s caused by something that my code is doing wrong or perhaps something incompatible with the particular setup of the user who experienced this exception?

I notice that the description below says that memory is corrupt. Does it mean that the user’s computer has bad RAM???

  ************** Exception Text **************
  System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
     at System.Drawing.SafeNativeMethods.Gdip.GdipDrawRectangleI(HandleRef graphics, HandleRef pen, Int32 x, Int32 y, Int32 width, Int32 height)
     at System.Drawing.Graphics.DrawRectangle(Pen pen, Int32 x, Int32 y, Int32 width, Int32 height)
     at System.Windows.Forms.ControlPaint.DrawFlatCheckBox(Graphics graphics, Rectangle rectangle, Color foreground, Brush background, ButtonState state)
     at System.Windows.Forms.ControlPaint.DrawFlatCheckBox(Graphics graphics, Rectangle rectangle, ButtonState state)
     at System.Windows.Forms.ControlPaint.DrawCheckBox(Graphics graphics, Int32 x, Int32 y, Int32 width, Int32 height, ButtonState state)
     at System.Windows.Forms.ControlPaint.DrawCheckBox(Graphics graphics, Rectangle rectangle, ButtonState state)
     at System.Windows.Forms.CheckedListBox.OnDrawItem(DrawItemEventArgs e)
     at System.Windows.Forms.ListBox.WmReflectDrawItem(Message& m)
     at System.Windows.Forms.ListBox.WndProc(Message& m)
     at System.Windows.Forms.CheckedListBox.WndProc(Message& m)
     at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
     at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
     at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:00:26+00:00Added an answer on June 12, 2026 at 9:00 pm

    Without more code, it’s hard to say exactly. Here are some things to note.

    .NET is a managed environment and one of its founding principles is the ability to validate code at compile time. Specifically, this means that certain guarantees may be made about a unit of code, such as:

    • Inability to read beyond the bounds of an array
    • Inability to modify function pointers
    • Inability to read/modify code segments of memory
    • Inability to confuse the type of an object reference

    Attempting to do these will either fail at compile time, or at run time with an exception.

    The exception you’re seeing comes as a consequence of ‘unsafe’ code. Unsafe is a bit of a misnomer really — it is better described as ‘unverifiable’. Sometimes, for performance reasons, it’s necessary to give up the verifiability of code in exchange for raw speed through things like pointer arithmetic.

    this app has no unsafe code.

    WinForms makes extensive use of ‘unsafe’ code. It’s truer to say that your assembly doesn’t have any unsafe code, but that it depends upon library code that is unsafe.

    I notice that the description below says that memory is corrupt. Does it mean that the user’s computer has bad RAM?

    Bad RAM is a possibility, but quite unlikely. Memory is corrupt when the values expected to be there are not actually there. This can be due to hardware fault, but also to software errors. This exception is usually raised in response to software errors in my experience. Also the message says that memory might be corrupt.

    The stack trace may not actually be very insightful here, as the memory is likely to have been corrupted at some earlier time, and was only detected during the stack frame you see here.

    there is 1 platform invoke call to user32.dll’s ShowWindow function (ShowWindow(p.MainWindowHandle, SW_SHOWDEFAULT);), but this call takes place before the message loop is started.

    This may well be the culprit. Have you tried using the managed Window.Show method instead? It may be that your window doesn’t have a handle yet, or that it changes, or that any number of things went wrong because of this. Generally try to avoid PInvoke when using managed wrappers on top of native stuff.

    Unfortunately without seeing more of your code, it’s impossible to provide a more useful answer, but hopefully the above provides some context onto the exception and may help you find out what your application is doing to get WinForms into this state.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to make an application uninstall itself? For example: I want
I am trying to write a reporting module for my application, the application itself
I'm programming a Google Maps based Android application. The application itself runs fine, without
How can an application authenticate itself to a server? Lets say I release an
How can I have my application minimize itself to the system tray in WindowsXP/Vista?
I'm writing a Cocoa application that installs itself as an menulet in the menu
I'm looking for a good way to tell my Cocoa application to quit itself.
I want my WinForms application to create an instance of itself for each screen
I am creating a software application that is able to update itself. After the
I'm building an application where I'll have a SwingWorker thread that in itself spins

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.