title: "Object reference not set to an instance of an object" when creating a new Web API controller with EF Scaffolding in Visual Studio 2012
body: <p>I have an MVC4/Web API project, with an Entity Framework, Code First data model. When I try to create a new API Controller with read/write methods using a data context &amp; model, I get an alert saying "Object reference not set to an instance of an object".</p>
  
  <p>I've done a bit of searching and found that some causes are incorrect project type Guids in the .csproj file, incomplete installation of the MvcScaffolding nuget package and one suggestion of installing Powershell 3. </p>
  
  <p>I have made sure all my project type guids are correct, made sure the MvcScaffolding package is installed correctly, and I've even installed Powershell 3. </p>
  
  <p>None of this has solved the problem for me. All I can think is there is a problem with my data context/model although it created the tables/relationships fine. Code below:</p>
  
  <p><strong>Context:</strong></p>
  
  <pre><code>public class PropertySearchContext : DbContext 
  {
      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          modelBuilder.Entity&lt;Property&gt;().HasRequired(p =&gt; p.Office).WithMany(o =&gt; o.Properties).HasForeignKey(p =&gt; p.OfficeId);
      }
  
      public DbSet&lt;Office&gt; Offices { get; set; }
      public DbSet&lt;Property&gt; Properties { get; set; } 
  }
  </code></pre>
  
  <p><strong>Model:</strong></p>
  
  <pre><code>[Serializable]
  public class Property
  {
      public int PropertyId { get; set; }
      public string Address1 { get; set; }
      public string Address2 { get; set; }
      public string Town { get; set; }
      public string County { get; set; }
      public string Postcode { get; set; }
  
      public int Bedrooms { get; set; }
      public int Bathrooms { get; set; }
  
      public string UmbracoNodeId { get; set; }
      public string MainImageUrl { get; set; }
      public string ListingImageUrl { get; set; }
      public int TotalImageCount { get; set; }
      public PropertyType PropertyType { get; set; }
      public PropertyStatus PropertyStatus { get; set; }
      public long Price { get; set; }
      public string ListingUrl { get; set; }
  
      //Navigation Properties
      public int OfficeId { get; set; }
      public virtual Office Office { get; set; }
  
      //Meta properties
      public DateTime CreatedAt { get; set; }
      public string CreatedBy { get; set; }
      public DateTime UpdatedAt { get; set; }
      public string UpdatedBy { get; set; }
  }
  </code></pre>
  
  <p><strong>Connection String:</strong></p>
  
  <pre><code>&lt;add name="PropertySearchContext" connectionString="Data Source=MERCURY\SQLEXPRESS;Initial Catalog=DATABASE_NAME;Integrated Security=False;User ID=dbFakeUser;Password=fakePassword;Connect Timeout=10" providerName="System.Data.SqlClient" /&gt;
  </code></pre>
  
  <p>Any help with this would be greatly appreciated as I've tried every suggestion and I still can't create a controller with scaffolding. Driving me mad!</p>
  
  <p>Thanks!</p>