Question

I have a problem with the application state in Asp.net. I need a list of Strings that i would use in different forms in the same application. Here I add the list:

Application.Add("users", new List<String>());

In a new form I try to add a string to the list, but I get NullReferenceException in the second line of the code below.

 List<String> ls=(List<String>) Application.Get("users");
            ls.Add(TextBox4.Text);
Was it helpful?

Solution

In the first slot of code the string is empty because of {new List<String>()}. You need to add the string in the list. Only after that, call the Application variable in another form to avoid the NullReferenceException Exception.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top