The error AccessViolationException: "Attempted to read or write protected memory". What could be the problem?

In essence she was asked to do a dropdown list of users (combobox). After the list is selected by some user, it is added to a specific file, then a field combobox'again freely to enter.
Implementation: In the field combobox'a start to enter the name, there is a drop down list with users whose name coincide with the entered. The matching is implemented through a request to the IPA server(use JIRA), then the resulting list is processed and stored in an array, then the list is displayed in the combobox.

Problem: sometimes the code works consistently, but sometimes, every 4-5 requests the error AccessViolationException "Attempted to read or write protected memory. This often indicates that other memory is corrupt."
I would like to resolve this issue. Before the error appeared more often, I thought that the server blocks the abuse, so the request was to send every 4 characters. Then the problem was forgotten until the program used in the normal operating mode.
public void dropDownList(ComboBox comboBox)
{
 comboBox.Text = comboBox.Text;
 string text = comboBox.Text;

 string url = "https://serverAddress/api/2/user/picker?maxResults=7&query=" + text;

 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

 request.CookieContainer = new CookieContainer();
 request.Method = "GET";
 request.ContentType = "application/json; charset=utf-8";
request.CookieContainer.Add(Session.cookies);
try
{
 using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
 Stream stream = response.GetResponseStream();
 JsonSerializer jsonSerializer = new JsonSerializer();

 using (StreamReader reader = new StreamReader(stream))
{
 using (JsonTextReader jsonTextReader = new JsonTextReader(reader))
{
 var obj = jsonSerializer.Deserialize(jsonTextReader);
 string jsonString = @JsonConvert.SerializeObject(obj);

 JObject jObject = JObject.Parse(jsonString);
 JArray array = (JArray)jObject["users"];
comboBox.Items.Clear();
 comboBox.SelectionStart = text.Length;
 int count = array.Count;
 userArray = new string[count];
 string temp = "";

 for (int i = 0; i < count; i++)
{
 temp = string.Format("{0}", array[i]["html"]);
 temp = temp.Replace("strong>", "").Replace("<", "").Replace("/", "");
 userArray[i] = temp;
 temp = "";
}

comboBox.Items.AddRange(userArray);
 Array.Clear(userArray, 0, count);
}
}


}
}
 catch 
{
 MessageBox.Show("something went wrong");
}
 }
June 8th 19 at 17:26
2 answers
June 8th 19 at 17:28
This error can only occur in unmanaged code.

PS: what version of the framework? In the 4th SEH exceptions by default are not caught.
Version 4.5 - norma_Bo commented on June 8th 19 at 17:31
, i.e. there is unhandled exception and the app collapses?
If so, see system event log subkey application - cole_Rutherford commented on June 8th 19 at 17:34
today this error is not appearing:( - norma_Bo commented on June 8th 19 at 17:37
we watched the logs, it says about the error appcrash in module shell32.dll. Found solutions to offer something to adjust/fix in windows. It does not suit me, because computers that use this program a lot. - norma_Bo commented on June 8th 19 at 17:40
June 8th 19 at 17:30
1. In The "AssemblyInfo.cs" you need to add:
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]


2. Instead of:
catch
{
 MessageBox.Show("something went wrong");
}


it is better to do:
catch (Exception ex)
{
Debug.WriteLine(ex);
MessageBox.Show(ex.Message);
}


As a result, you will get a detailed description and indication of the source of the problem (see output window in the debugger).

P. S. I would Venture to suggest that nerovnosti the guys from NewtonSoft.

Find more questions by tags C#API