You must Sign In to post a response.
  • Category: ASP.NET

    Object reference not set to an instance of an object.

    Hi developers,
    Many times i got this type of error.i just know what is it but i don,t know the exactly meaning of this type of error.Please say what is the meaning for it.
    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

    Thanks with,
    Paul.S
  • #762133
    Hello Paul Raj,

    Object reference not set to an instance of an object, this type of errors occurs when you are trying to pass any reference from your object to another object.

    NullReferenceException is common. It indicates that you are trying to access member fields, or function types, on an object reference that points to null.

    Can you share your code with us, so that we can try to solve your problem and gives you the proper solution and faster result.

    use this code :

    try
    {
    // your code goes here
    }
    catch(Exception ex)
    {
    MessageBox.Show(ex.StackTrace);
    }

    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #762134
    Hi
    Paul

    Mostly this type error occur

    System.NullReferenceException: Object reference not set to an instance of an object.

    following reason

    1. We didnt mention proper object name.
    2. We didnt create new new instance from the object
    3. We didnt proper datatype conversion


    For ex:

    We declare Datatable this


    dt=dt1;


    Check proper control mention then you have retrieve the proper value or not check them

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #762153
    Hi PaulRaj,

    When you are assign null value to some object in that scenario you may get this type of error. So, before assign value to object check the condition whether object contains value or not. If there is no value then skip the assign operation.

    Hope this will helpful to you..

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #762174
    Hi

    Let me correct you "Object reference not set to an instance of an object" is an exception, not the error.

    Error is the one we can't solve , exception is the one we can find solution for it.

    Object reference not set to an instance of an object exception occurs when you try to access an object to which you haven't given any value. In such cases it throws the exception.

    Regards

    Sridhar Thota.

    Sridhar Thota.
    Editor: DNS Forum.


Sign In to post your comments