title: ASP.NET 4.0 server error - "object reference not set to an instance of an object" on 32bit Virtual Machine
body: <p>We are receiving an error that has been difficult to find a cause for.  The error message being displayed is "Object reference not set to an instance of an object."  I understand what it is saying, and we have found the object that is NULL, but we cannot determine why it is occurring.</p>
  
  <p>The application is an ASP.NET 4.0 app. After logging in, the system checks an Application variable that is set in Session_Start().   The variable is null and causing this error (see below for full error message displayed).  </p>
  
  <p>We have found that this occurs only on a 32-bit virtual machine.  Here are some that we tested on:</p>
  
  <ul>
  <li>XP virtual - server error</li>
  <li>XP non-virtual - works</li>
  <li>2003 32bit virtual - server error</li>
  <li>2003 32bit non-virtual - works</li>
  <li>2008 64bit non-virtual - works</li>
  <li>2008 32bit virtual - server error</li>
  <li>2008 64bit virtual - works</li>
  </ul>
  
  <p>We tested by moving the entire project to the virtual machine and compiled it using VS 2010 Express.  The application then worked correctly.  The application then worked correctly.  Therefore, it seems that if this application is precompiled, on a 32bit virtual machine, the NullReferenceException error will appear.</p>
  
  <p>Since we have proven this works on most machines, we are confident it is not the code.  What do we need to check now?  Is there something that is not installed on the virtual machines?  Any suggestions of things to look for or try would be appreciated.  If you need me to clarify something or give more information, please let me know.</p>
  
  <blockquote>
    <p>Server Error in '/TestSite'
    Application. 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.</p>
    
    <p>Exception Details:
    System.NullReferenceException: Object
    reference not set to an instance of an
    object.</p>
    
    <p>Source Error:</p>
    
    <p>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.</p>
    
    <p>Stack Trace:</p>
    
    <p>[NullReferenceException: Object
    reference not set to an instance of an
    object.]<br>
    HomeMasterPage.Page_Load(Object
    sender, EventArgs e) +204<br>
    System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr
    fp, Object o, Object t, EventArgs e)
    +14    System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object
    sender, EventArgs e) +35<br>
    System.Web.UI.Control.OnLoad(EventArgs
    e) +91<br>
    System.Web.UI.Control.LoadRecursive()
    +74    System.Web.UI.Control.LoadRecursive()
    +146    System.Web.UI.Page.ProcessRequestMain(Boolean
    includeStagesBeforeAsyncPoint, Boolean
    includeStagesAfterAsyncPoint) +2207</p>
    
    <p>Version Information: Microsoft .NET
    Framework Version:4.0.30319; ASP.NET
    Version:4.0.30319.1</p>
  </blockquote>
  
  <p><strong>updated after comments</strong></p>
  
  <pre><code>void Application_Start(object sender, EventArgs e) 
      {
          // Code that runs on application startup
          ArrayList ArrActiveUser = new ArrayList();
          Application["ArrActiveUser"] = ArrActiveUser;
      }
  
  ...
  
  
      void Session_Start(object sender, EventArgs e) 
      {
          // Code that runs when a new session is started
          ArrayList ActiveUsers = new ArrayList(); 
          if (Application["ArrActiveUser"] != null)
          {
              ActiveUsers = (ArrayList)Application["ArrActiveUser"];
          }
          ActiveUsers.Add(Session.SessionID);
          Application["ArrActiveUser"] = ActiveUsers;
      }
  </code></pre>