© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
3 replies
Diesel Geezer

System.AccessViolationException: Attempted to read or write protected memory.

i get this exception when i change a multiline textbox to single line:
Visual studio actually throws the exception at the Program.cs at the Application.Run(new Form1()); line, but i found that the issue is caused by the line valTxtBox.Multiline = false; because if i remove it i dont get the exception
What is going on here?
cs 
valTxtBox.TextChanged += (_, _2) =>
{
    if (valTxtBox.Text.Contains('\n'))
    {
        disableTxtBoxAutoClose = true;
        valTxtBox.Multiline = true;
        valTxtBox.Height = 20 + 100;
        valTxtBox.Focus();
        disableTxtBoxAutoClose = false;
    }
    else
    {
        disableTxtBoxAutoClose = true;
        valTxtBox.Multiline = false; <<-PROBLEM CAUSED BY THIS?
        valTxtBox.Focus();
        valTxtBox.Text = boxText;
        disableTxtBoxAutoClose = false;
    }
cs 
valTxtBox.TextChanged += (_, _2) =>
{
    if (valTxtBox.Text.Contains('\n'))
    {
        disableTxtBoxAutoClose = true;
        valTxtBox.Multiline = true;
        valTxtBox.Height = 20 + 100;
        valTxtBox.Focus();
        disableTxtBoxAutoClose = false;
    }
    else
    {
        disableTxtBoxAutoClose = true;
        valTxtBox.Multiline = false; <<-PROBLEM CAUSED BY THIS?
        valTxtBox.Focus();
        valTxtBox.Text = boxText;
        disableTxtBoxAutoClose = false;
    }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

System.AccessViolationException: Attempted to read or write protected memory.
C#CC# / help
2y ago
❔ system.accessviolationexception: attempted to read or write protected memory
C#CC# / help
3y ago
❔ System.AccessViolationException: 'Attempted to read or write protected memory.
C#CC# / help
4y ago
System.AccessViolationException
C#CC# / help
4y ago