Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET4
Hi
 
When i debug my application on my system it works fine without any error. But when i publish it and browse the virtual directory on the localhost, static pages are working fine but when inserting the data into the database or retrieving the data from the database it shows me the following error. Kindly can i know why am getting that error and how can i slove 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.
 
Source Error:
 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
 
Stack Trace:
 

[NullReferenceException: Object reference not set to an instance of an object.]
home.bindDataList() +63
home.Page_Load(Object sender, EventArgs e) +5
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
 
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
Posted 8-Apr-13 21:20pm
Comments
Sergey Alexandrovich Kryukov at 9-Apr-13 2:32am
   
What's the use of showing the exception stack, if you don't show the code?..
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You did not show the code fragment where the exception with the message "Object reference not set to an instance of an object" is thrown.

Not to worry. This is one of the very easiest cases to detect and fix. It simply means that some member/variable of some reference type is dereferenced by using and of its instance (non-static) members, which requires this member/variable to be non-null, but in fact it appears to be null. Simply execute it under debugger, it will stop the execution where the exception is thrown. Put a break point on that line, restart the application and come to this point again. Evaluate all references involved in next line and see which one is null while it needs to be not null. After you figure this out, fix the code: either make sure the member/variable is properly initialized to a non-null reference, or check it for null and, in case of null, do something else.
 
Please see also: want to display next record on button click. but got an error in if condition of next record function "object reference not set to an instance of an object"[^].
 
Good luck,
—SA
  Permalink  
Comments
Maciej Los at 9-Apr-13 2:36am
   
+5
Sergey Alexandrovich Kryukov at 9-Apr-13 8:26am
   
Thank you, Maciej.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Not to many details...
 
See this: System.NullReferenceException – Object reference not set to an instance of an object. 3 common causes in VB.Net.[^].
 
Next time be more specific and provide more details.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 475
1 Maciej Los 349
2 Richard MacCutchan 220
3 BillWoodruff 219
4 Mathew Soji 160
0 OriginalGriff 8,759
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,269
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411028.1 | Last Updated 9 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100