The asp.net run prompts that the object reference is not set to the instance error resolution of the object

  • 2020-05-17 05:05:43
  • OfStack

The object reference is not set to an instance of the object
1. The expression "1" on the Internet
1. The object of ViewState is Null.
2. DateSet is empty.
3. DataReader is empty because of the sql statement or Datebase.
4, declare a string variable without assigning a null value to the variable.
5. The object is not initialized with new.
6. The Session object is empty.
7. When assigning a text value to the control, the value does not exist.
8. When Request.QueryString () is used, the obtained object does not exist, or no initial value is assigned when the value is null.
9. When FindControl is used, the control does not exist but has not been preprocessed.
10. Duplicate definition causes an object reference not to be set to an instance of the object.
2.
(1) the set variable is null or has no value. This problem usually occurs when parameters are passed, and it also occurs when data controls such as DataGrid or gridview or datalist are used.
(2) the control name does not correspond to the one in codebehind
(3) the object is not initialized with new
(4) the control referenced in the program does not exist
Solutions:
(1) using try.. catch... finally catches errors, or simply outputs the value of the variable with response.write ()
(2) check whether there are any uninitialized variables in the code
3. SqlConnection.Open does not set an object reference to an instance of the object
When developing the ASP.NET program using VS2003, it sometimes occurs when the Open() method of the SqlConnection object is manipulated
The object reference is not set to an instance of the object.
Note: an unhandled exception occurred during the execution of the current Web request. Check the stack trace information for more information about this error and the source of the error in the code.
Exception details: System.NullReferenceException: the object reference is not set to an instance of the object.
Sources of error:
.
conn.Open();
......
Trace debugging can also be sure to perform new operations on conn, but the program often reports errors at this point, but sometimes restarts the server or restarts IIS and it works. If you can't find the problem through debugging, you may have installed the NETFRAMEEWORK framework on your own machine. There is something wrong with the NETFRAMEEWORK framework, may not have installed the SP1.1 patch
Need to play NET reproduced from percentage net http: / / www oh100. com, please keep this tag FRAMEEWORK1. 1 SP1 patch, to Microsoft's official website to download after installation.
4. 1 I personally summarize the following situations when abnormal NullReferenceException appears as follows:
1. There is no reference to the namespace where the object resides
2. Object is not instantiated
3. If there is an exception, the failed instantiation object is null
5. When IIS can't handle it, it will make the above mistakes.
When an application gets more users than it can handle, an error occurs.
Improve your application, use caching, and minimize the number of interactions with the database.
6. The problem I have encountered is that I accidentally reset the DataSet reference. Please check your code carefully to see if you have re-referenced it somewhere else.
7. When you find that all your methods don't work, put in the.netframework patch
8. I made this error just because the dll file of DAL in the website was invalid, and the business layer could not instantiate the object inside IDAL
But also wasted 1 afternoon time on the code
9.
Add monitoring for every suspicious place. At first, I thought that the sql statement was wrong. I checked it several times, but the same error was reported when I used sql. According to the results from google, the reference to object redefinition will result in this result. Following this 1 tip, you can replace the page-level global objects and you are done.
classDBOper{
The /* constructor has no body
**c# writes a series 1 operation method on the database
**} initially, to save the trouble of declaring as few objects as possible, only one privateDBOperdb=newDBOper() was declared globally, and the methods of this object were called in different methods to avoid wasting memory by defining them. The code was subsequently refactored and no errors were reported at compile time. But when run, "NullReferenceException: no object reference set to an instance of the object "appears. It ended up costing me hours. Later, according to the results of google, the DBOper object 11 used in different methods was redefined as a local variable (only one DBOper object was defined in one method, and its methods were normal after multiple calls), and the global private variable was removed. It will work when it is running again.
It is not clear why this problem arose when custom objects were raised as class and used as private in different methods

Related articles: