C #: Object reference not set to an instance of an object-summary of possible issues (GO)

Source: Internet
Author: User
Tags stack trace microsoft website

Excerpt from: http://blog.csdn.net/sollion/article/details/5777475

I. GENERAL statements on the Internet

1, the ViewState object is null.
2, Dateset empty.
3, the SQL statement or datebase cause DataReader empty.
4. When declaring a string variable, the variable is applied without assigning a null value.
5. The object is not initialized with new.
6. The Session object is empty.
7. When assigning a text value to a control, the value does not exist.
8. When using Request.QueryString (), the obtained object does not exist, or the initial value is not assigned when the value is empty.
9, when using FindControl, the control does not exist but does not do preprocessing.
10. Duplicate definition causes an instance error that does not set the object reference to an object.

Second, (1) The variable being set is NULL or does not have a value, it usually occurs when passing parameters, and also occurs when using data controls such as the DataGrid or GridView or DataList.

(2) The control name does not correspond to the inside of the codebehind

(3) object not initialized with new

(4) The control referenced in the program does not exist

Workaround:

(1) Use try: Catch...finally catch error, or output the variable value directly with Response.Write ()

(2) To see if there are uninitialized variables in the code

Third, Sqlconnection.open object reference not set to an instance of an object

Use VS2003 to develop ASP. NET program sometimes occurs when you manipulate the open () method of a SqlConnection object

Object references are not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current WEB request. Check the stack trace information For more information about the error and the source of the error in your code.

Exception Details: System.NullReferenceException: Object references are not set to an instance of an object.

SOURCE Error:
。。。。

Conn. Open ();

......

Trace debugging will certainly be able to determine the new operation of the Conn, but the program often errors in this place, but sometimes restarting the server or restarting IIS can be used normally. How to debug and can not find the problem then this time may be your local installation of the. NET frameework Framework has a problem, may not have not installed SP1.1 patch
Need to hit the net FRAMEEWORK1.1 SP1 patch, to the official Microsoft website after downloading the installation is good.

Four, in general, I have a summary of NullReferenceException anomalies in the following situations:

1. The namespace in which the object resides is not referenced
2. Object Not instantiated
3, an exception occurs, the instantiation of the failed object is null

Five, The error will also occur when IIS is unable to carry it.

An error occurs when the user's access to the application exceeds the range it can withstand.
Improve your programs, use caching, and minimize the number of interactions with your database.

Six, The problem I came across was that I had no intention of resetting the dataset reference, and then I asked you to check your code and see if it was re-referenced elsewhere, and in my program the dataset was set as a global object.

Seven, when you find that all the methods are not working, hit the. NETFramework Patch

Eight , I have this error, just because the website inside the dal DLL file invalidation, the business layer can not be instantiated idal inside the object

But also wasted an afternoon on the tune code

Nine, for each suspicious place to add monitoring, at first thought that the SQL statement was wrong, checked several times, swapping SQL statements or reporting the same error. Based on Google's results, the mention of object redefinition can result in this. Based on this hint, replace the page-level global object, and finally it's done.

Class dboper{
/* constructor does not have a function body
*
*c# write a series of methods for database operation
*
*
}
Initially for the sake of convenience, as little as possible to declare objects, only in the global declaration of a private Dboper db=new dboper (), in different methods to invoke the method of the object, in order to avoid the definition of the memory waste. Later code refactoring, not error when compiling. However, when running, the "NullReferenceException: Object reference is not set to an instance of an object" appears. The result was a couple of hours of doing it. Later, according to Google's results, the different methods used in the Dboper object one by one is defined as a local variable (a method that only defines a Dboper object, multiple calls to its methods are normal), remove the global private variable. It's normal to run again.
The question of why a custom object has been made into a class for private use in a different way is not clear at this time .................

C #: Object reference not set to an instance of an object-summary of possible issues (GO)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.