title: "Object reference not set to an instance of an object" error when running app
body: <p>I have this code that is supposed to load the attributes of an XML file to a string variable when the user clicks a button:</p>
  
  <pre><code>    public void Button1_Click(object sender, EventArgs e)
      {
          XDocument doc = XDocument.Load("C:/Structure.xml");
          Visit(doc.Root);
  
  
      }
  
      public static void Visit(XElement element)
      {
  
          string siteURL1 = element.Attribute("URL").Value;
          string siteTitle1 = element.Attribute("siteTitle").Value;
          string siteDescription1 = element.Attribute("siteDescription").Value;
          string siteTemplate = element.Attribute("siteTemplate").Value;
          string name = element.Attribute("type").Value;
          Execute(name, siteURL1, siteTitle1, siteDescription1, siteTemplate); 
  }
  </code></pre>
  
  <p>But when I deploy the webpart, and click the button, I get the "NullreferenceException was unhandled by user code / Object reference not set to an instance of an object" errors. on:</p>
  
  <pre><code>  string siteURL1 = element.Attribute("URL").Value;" 
  </code></pre>
  
  <p>Any idea of what I may be doing wrong?</p>
  
  <p>This is what the structure looks something like this:</p>
  
  <pre><code>&lt;root&gt;
    &lt;level1 name="level1A"
            type="Private"
            template="3 
            siteTitle="Private"
            siteDescription="Private Site"  
            URL"private"&gt;
      &lt;level2 name="level2A"&gt;
        &lt;level3 name="level3A"&gt;
          &lt;level4 name="level4A"&gt;
            &lt;level5 name="level5A"&gt;
              &lt;level6 name="level6A"&gt;
                &lt;level7 name="level7A"&gt;
                  &lt;level8 name="level8A"&gt;&lt;/level8&gt;
                &lt;/level7&gt;
              &lt;/level6&gt;
            &lt;/level5&gt;
          &lt;/level4&gt;
        &lt;/level3&gt;
      &lt;/level2&gt;
    &lt;/level1&gt;
  &lt;/root&gt; 
  </code></pre>