1

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);
1
  • 1
    Please add some more code, like where EXACTLY do you add the list to the Application object Commented Nov 7, 2012 at 8:36

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Correct, need to add { } after the constructor parenthesis.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.