AccessViolationException while typing a text box
About a week ago, a program I'm working on started crashing with an AccessViolationException whenever I entered a specific text field. I've reduced it down to this test case, but I have no idea:
Imports System.Windows.Forms
Public Class Start
Inherits System.Windows.Forms.Form
<STAThread()>
Public Shared Sub Main(args() As String)
Application.EnableVisualStyles()
Application.Run(New Start())
End Sub
Private txtNotes As System.Windows.Forms.TextBox
Public Sub New()
Me.txtNotes = New System.Windows.Forms.TextBox()
Me.txtNotes.Multiline = True
Me.Controls.Add(Me.txtNotes)
End Sub
End Class
When I create this program with Visual Studio, it resets if I enter text in the text box (always). If I build it with it vbc.exe Start.vb /target:winexe /main:Start /out:Start.exe
, it works fine.
Also, I found that deleting one of these lines stops it on failure with Visual Studio:
Application.EnableVisualStyles()
Me.txtNotes.Multiline = True
I have already performed a repair install of Visual Studio and used sfc.exe
to check for corrupted system files. I tried to find existing solutions to this problem but didn't find anything. What can cause Visual Studio to build a broken executable? Are there any settings that would do this?
Edit: I'm running AVG antivirus as well for now. I remember there was an AVG update during these glitches. As per one of the comments below, disabling AVG and then scanning the executable prevents it from crashing. This seems to indicate that the problem is with AVG.
source to share
We have the same problem installing several of our clients on Windows 7. Our product is C # with WinFoms and .net 4.0. Typing text in a mutli-line textbox under WinForms throws AccessViolationException. You can paste text in the field and delete it too, just don't type. Single line text boxes are fine. We also found that removing Application.EnableVisualStyles () fixed the issue.
Another way to fix this without changing your code is to right-click the program icon and change the compatibility settings to launch the Windows 7 program.
source to share
I have the same problem and I am running AVG too.
As a workaround before AVG provides a fix, you can add the .exe file to AVG's exclusion list. I can confirm that this removes the AccessViolationException shown in Visual Studio.
- Open AVG, open "Options"
- "Additional settings..."
- Exceptions
- "Add an exception"
- Select "Application or File"
- Select the executable (in my case I used ... /bin/Debug/myexe.exe)
- I checked "Even when the file was changed or updated"
- Finally, I checked all three options at the bottom: "Resident Shield", "Manual and Scheduled Scan" and "Identity Protection".
I haven't made any changes regarding visual styles or compatibility mode as mentioned in other answers.
source to share
I had the same problem. Chose it by unchecking Enable XP visual styles.
Some background in case it helps someone else. The app was built in VS2010. Moved to VS2015RC. Everything worked fine. The problem arose after reinstalling the OS (Win7). Even the old version of the application won't work, although it continued to work on all other Win7 desktops, including a fresh install. If anyone knows why it would be interesting.
source to share