AccessViolationException when typing in multilined TextBox RRS feed

  • Question

  • About one or two weeks ago I suddenly got an AccessViolationException, and I am still getting it, when typing in a multilined TextBox. I don't get it when deleting or pasting text in it. I hadn't changed anything in the code so I can't understand why I get this exception. I have tried to delete the control and recreate it with the properties I want it to have and I discovered that it was the multiline property that causes the exception. I don't get the exception if the multiline property is set to false. I created a new WindowsFormsApplication with only a multlined TextBox and got the same exception. I have also discovered that deleting the line Application.EnableVisualStyles(); in Program.cs prevents the application from crashing. 

    What could have happened? What should I do to fix the problem?

    Thankful for answers!

    • Moved by CoolDadTx Monday, August 17, 2015 3:15 PM Winforms related
    Friday, August 14, 2015 11:05 AM


  • I just added my .exe-file to AVG's exception list and now I can type in the TextBox again :)
    • Marked as answer by 365T Thursday, August 20, 2015 8:04 PM
    Thursday, August 20, 2015 8:04 PM

All replies

  • AccessViolationException usually means one of two things:

    - you are using unmanaged code and somebody of course messed up the pointer arithmethic. Any COM libraries or old API calls in your code?

    - the memory (RAM) or file on the disk is faulty. So a hardware or installation defect.

    Is the error happening on other computers/windows installations or only your development machine?
    Could it be some automatic update (Windows, new virus scanner) messes up a windows/.NET Framework file?

    Friday, August 14, 2015 6:34 PM
  • It's my understanding that styles are only supported on xp and Windows Server 2003:

    If you're not targeting those then you can just remove the line


    And you're done.

    If you ARE using them then it's related to the interaction between system theme and a multiline textbox.

    Friday, August 14, 2015 6:58 PM
  • I'm not targeting those and removing the line solves the exception problem. But it also causes a quite decrease of the design for some controls. It looks like a program for Windows 98. 
    Saturday, August 15, 2015 3:22 PM
  • Windows 98?? Are you telling us you are still running C# Winform in Windows 98?? Windows 98 life ended in April 1, 2007. If you are running Windows 98 then upgrade your OS and upgrade your PC if it does not support the OS. I really bet this is the answer you are going to get even you call Microsoft.



    Saturday, August 15, 2015 3:36 PM
  • I'm not using any additional libraries. I've tried on another computer, also Windows 7 as my computer, and I didn't get the exception. That points to that it has to do with just my computer. Especially because the problem has occured without me doing anything. I will reinstall the .NET Framework and check if that solves the problem.
    Saturday, August 15, 2015 3:50 PM
  • One of my users, who is running Windows XP, is having this problem.  Other users of Windows XP have no problem.  If I understand what you are saying, this is happening because the user with the problem has a "bad" choice of system theme, and the only solution is to get this user to change his theme.

    I am running Windows 7 Pro, but also have installed Windows XP (Service Pack 3) on a virtual machine.  My software runs fine on both Windows 7 and also the virtual Windows XP.  I'm not even sure how you set the "system theme" in Windows XP.  I've looked in Control Panel both System and Display and find nothing about "theme."  So I don't know what to suggest to my user.  I would like to set the theme to whatever setting causes this problem.

    I do have the line"Application.EnableVisualStyles()" but you seem to be saying that removing it would have no effect.

    Thanks in advance for any help with this.

    Michael Bate

    Saturday, August 15, 2015 9:59 PM
  • Just to be on the save side, you should also run a Ram check like memtest (avialible from any Linux DVD).

    Faulty RAM can be quite insidious and hard to notice. A windows can operate for months or years despite faulty ram, there will just be odd occurences like scrambeled files, scrambeled rights or suddenly 90% of your user files being missing from the filesystem (had all of those, but not on same computer).

    Saturday, August 15, 2015 11:41 PM
  • I was maybe a bit unclear about the Windows 98 thing, I'm running Windows 7. I meant that deleting Application.EnableVisualStyles(); solves the problem with not being able to type in the multilined TextBox but it also causes a loss in design. For example: the headers to the ListViews changes in shape and color.

    Reinstalling .NET Framework did not solve my problem (being able to type in the TextBox without having to delete Application.EnableVisualStyles();). I will have to check the RAM.

    Tuesday, August 18, 2015 7:27 PM
  • I now have the exact same issue.  Typing into a multi line textbox cause an access violation.  It happens on all my projects regardless of the .NET framework (I have project on .NET 2.0 and 4.0).  If I start a brand new project with a clean form, add a multiline textbox and run it I get the same exception. I'm running windows 7 with Visual Studio 2010.  I have also restored some of my earlier project backups and they have the same behavior.  I have also tried resetting the Visual Studio settings (Tools -> Import and Export Settings -> Reset All Settings).

    The one thing I did notice is that I've started to get the "Get Windows 10" balloon popup from the icon in the system tray now.

    Thursday, August 20, 2015 1:02 AM
  • Update: This may be related to AVG Free 2015.  If you are running that, try disabling protection and see if that fixes the issue.
    Thursday, August 20, 2015 1:20 AM
  • Update: This may be related to AVG Free 2015.  If you are running that, try disabling protection and see if that fixes the issue.
    It fixed it but then I have no virus protection...
    Thursday, August 20, 2015 7:46 PM
  • I just added my .exe-file to AVG's exception list and now I can type in the TextBox again :)
    • Marked as answer by 365T Thursday, August 20, 2015 8:04 PM
    Thursday, August 20, 2015 8:04 PM
  • try change Architecture x68, x64... it also generate this error

    Saturday, January 19, 2019 11:43 AM