title: Checking that an Extensible Storage Schema exists before retrieving it's fields
body: <p>I have used an if statement to check if the method retrieving the schema is null, this is in a separate form that contains the checkedListBox to populate. The code is below and I have marked the conditional that checks for this. My question is;
     What is the most effective method to ensure that each time the revit add-in is run in a new .rvt file, the schema record already exists before attempting to retrieve a schema? When things go awry a null reference error occurs when trying to access an empty schema.               </p>
  
  <pre><code>           //CheckedListBox for filter01 this exists in the form and calls the main 
             class function to retrieve the record.
                  checkedListBox1.DataSource = WS.categoryList(rvtDoc, intSwitch = 1);
                  Filter01_CategoryList = new List&lt;BuiltInCategory&gt;();
  
  
                  **if (WS.retSchemaBICMethod(rvtDoc) != null)**
                  {
                      TaskDialog.Show("Schema 1 ", " exists");
                      Filter01_CategoryList = WS.retSchemaBICMethod(rvtDoc);
                  }
                  else
                  {
                      TaskDialog.Show("Schema 1 "," has not been created");
  
                      //Update stored schema field values 
                      inputBIC = checkedListBox1.CheckedItems.Cast&lt;BuiltInCategory&gt;
                      ().ToList&lt;BuiltInCategory&gt;();
                      WS.getSetBIC(rvtDoc, inputBIC);
                      WS.storeSchema(rvtDoc, WS.projectInfoElement, inputBIC,
                      out WS.retrieveBIC);
  
                      //set checkedlistbox 1
                      Filter01_CategoryList = WS.retSchemaBICMethod(rvtDoc);
  
                  }
  
  
         //this code returns the retrieved schema from the main class
      public List&lt;BuiltInCategory&gt;retSchemaBICMethod(Document doc)
      {
  
          Element piElement = projectInfoFilter(doc);
  
              // Read back the data from ProjInfo
              Entity retrievedEntity = piElement.GetEntity(Schema.Lookup(schemaGuid));
              IList&lt;int&gt; retrievedData = retrievedEntity.Get&lt;IList&lt;int&gt;&gt;
              (Schema.Lookup(schemaGuid).GetField("BuiltInCatIds"));
  
  
              //cast int list back to built-in category list
              retSchemaBIC = retrievedData.Cast&lt;BuiltInCategory&gt;
              ().ToList&lt;BuiltInCategory&gt;();
  
          return retSchemaBIC;
      }
  </code></pre>