title: ASP.Net String Assignment Failure
body: <p>This is my first post here, so go easy on me :)  I'm having an odd problem with an ASP.Net page.  I'm getting an object not set error message when assigning a string literal to a variable.  Here's the error I'm getting.</p>
  
  <blockquote>
    <p>[NullReferenceException: Object
    reference not set to an instance of an
    object.]<br>
    Project.Page.Page_Load(Object sender,
    EventArgs e) in
    C:\Project\Page.aspx.vb:10<br>
    System.Web.UI.Control.OnLoad(EventArgs
    e) +91<br>
    System.Web.UI.Control.LoadRecursive()
    +74    System.Web.UI.Page.ProcessRequestMain(Boolean
    includeStagesBeforeAsyncPoint, Boolean
    includeStagesAfterAsyncPoint) +2207</p>
  </blockquote>
  
  <p>And here is the code that the error is pointing to.  The last line in this fragment is the line 10 the error is complaining about</p>
  
  <pre><code>Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  
    Dim teststring As String
    teststring = "test"
  </code></pre>
  
  <p>It seems it fails on accessing any reference type, even if it is declared locally in the load function.  I originally found the problem when Request.IsSecureConnection was nulling out on me.  I eventually discovered I could replace it with the above code and fail in the same way. </p>
  
  <p>The problem does not always happen.  It seems to be triggered by publishing an update from Visual Studio, or when I head home for the day and the server sits idle all night.  One or two app pool recycles seems to clear it up, and the page functions correctly.</p>
  
  <p>Any help would be greatly appreciated.  I've been doing desktop development for a few years, but I'm fairly new to web development.  So maybe this is something obvious I've got configured wrong.  I'm currently using .Net 4 on IIS 6.  </p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I was able to identify the line using the recommendation of copying the page, commenting everything out, and then uncommenting one line at a time.  The line my test page started giving the error was this one</p>
  
  <blockquote>
    <p>Dim StateName As String = State.Attribute(XName.Get("name")).Value</p>
  </blockquote>
  
  <p>That code is in a foreach over an IEnumerable(of XElement).  The stack trace still points to the string assignment, but all other stack traces are spot on, so I don't think it's a bad pdb.</p>
  
  <p>Also, when the error occurred this time, no amount of recycling the app pool or stopping and starting it would fix the error.  I finally got it working again by switching the application to a different app pool.</p>