0

I had the following in my event log from my web server. Does anybody know what might be wrong? I researched on the Internet, but found nothing in terms of why it happens. I don't ask what NULL exception is. I very well know that. All I ask is that this exception is thrown from ASP.NET classes. Since I can't see Microsoft's implementation, I just want to know if anyone else has ever encountered the same exception with similar stack trace and how they handled this.

Exception type: NullReferenceException 
    Exception message: Object reference not set to an instance of an object.
   at Sample.Test..ctor()
   at __ASP.FastObjectFactory_app_web_qquiiyt1.Create_ASP_test_aspx()
   at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp)
   at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
   at System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
neo
  • 1,952
  • 2
  • 19
  • 39
  • Almost all cases of `NullReferenceException` are the same. Please see "[What is a NullReferenceException in .NET?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)" for some hints. – John Saunders Jan 02 '14 at 20:32
  • I know what it is, but I don't understand why this happens. These calls are done by ASP.net, not me. – neo Jan 02 '14 at 20:33
  • What is the `Test` class? Does it have any initialization or a constructor? Can you get this to fail in a Debug configuration so that you would have line numbers available to see where the crash occurs? – John Saunders Jan 02 '14 at 20:36

2 Answers2

0

Looks like you have a class named Test, the null reference is being thrown from the constructor of that class. Paste the Test class.

T McKeown
  • 12,971
  • 1
  • 25
  • 32
0

This type of Exception throws when a reference type has no instance.

For example:

List<CustomType> list;
CustomType item = new CustomType();
list.Add(item);

A NullReferenceException will occur when you add a new item to the list (Because list has no instance).

For your problem specifically you'll have to investigate at what point the exception occurred.

The stack trace tells you:

Sample.Test..ctor()

So I would look at that constructor.

You can use Log4Net which can provide with additional Assembly information which may help in identifying at what point the exception occured, also look for a try/catch block, in your case you've caught NullReferenceException or the generic Exception class which is bad practice.

  • You guys misunderstand me. I very well know what null reference exception is. The stack trace I show contains methods asp.net calls. Why these methods produce null reference exception is the question. – neo Jan 02 '14 at 20:40
  • One of your objects has no instance. Asking why it crashes is almost impossible for us to debug for you when we don't have the full code/not familiar with your system/you haven't told us why you think this happens. – user3155032 Jan 02 '14 at 20:43
  • These are asp.net calls. Someone might have encountered the same expection with this call stack. – neo Jan 02 '14 at 20:43
  • 1
    I would look at the constructor in `Sample.Test` – user3155032 Jan 02 '14 at 20:46