title: MVC 5 - The type arguments for method "..." cannot be inferred from the usage. Try specifying the type arguments explicitly
body: <p>I have been learning MVC 5 for the past couple of weeks. I have had little to no issues so far, until yesterday. Everything was working fine until last night when I opened up VS to work on my projects some.</p>
  
  <p>My issues:</p>
  
  <p>To get a few things out of the way, I have restarted my computer, repaired my VS installation, removed temp folders from AppData etc. I have exhausted every possible solution I could find. Now onto my issues.</p>
  
  <p>First of all, I stopped working on my current project and created a new project using the same database model. The database is an Azure SQL database. For each of the objects I created my own class to apply data annotations that looks like this: (I removed all the data annotations as there were quite a few. The error still persists)</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel.DataAnnotations;
  using System.Linq;
  using System.Text;
  
  namespace Dyad.GreenvilleFoodTrucks.Data
  {
  [MetadataType(typeof(LocationMetadata))]
  public partial class Location
  {
  }
  
  public class LocationMetadata
  {
      public int ID { get; set; }
      public int TruckID { get; set; }
      public Nullable&lt;System.DateTime&gt; StartTime { get; set; }
      public Nullable&lt;System.DateTime&gt; EndTime { get; set; }
      public Nullable&lt;System.DateTime&gt; Date { get; set; }
      public string Description { get; set; }
      public string Address { get; set; }
      public string State { get; set; }
      public string ZIP { get; set; }
  
      public virtual Truck Truck { get; set; }
  }
  }
  </code></pre>
  
  <p>And the object EF created from my database:</p>
  
  <pre><code>namespace Dyad.GreenvilleFoodTrucks.Data
  {
  using System;
  using System.Collections.Generic;
  
  public partial class Location
  {
      public int ID { get; set; }
      public int TruckID { get; set; }
      public Nullable&lt;System.DateTime&gt; StartTime { get; set; }
      public Nullable&lt;System.DateTime&gt; EndTime { get; set; }
      public Nullable&lt;System.DateTime&gt; Date { get; set; }
      public string Description { get; set; }
      public string Address { get; set; }
      public string State { get; set; }
      public string ZIP { get; set; }
  
      public virtual Truck Truck { get; set; }
  }
  }
  </code></pre>
  
  <p>I then made a scaffolded item using my newly created model with the context being the one that EF created, not ApplicationDBContext.</p>
  
  <p>Now when I go into the generated views, the ViewBag.Title = "title"; gives me this error:
  "One or more types require to compile a dynamic expression cannot be found. Are you missing a reference?" Note that this happens on all the CRUD cshtml files as well as the index.</p>
  
  <p>In addition to this, on every single @Html.LabelFor / @Html.DisplayNameFor as well as anything that ends in "For" gives me this error:
  "The type arguments for method 'System.Web.Mvc.Html.DisplayNameExtensions.DisplayNameFor(System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression>)' cannot be inferred from the usage. Try specifying the type arguments explicitly."</p>
  
  <p>Here is what a view look like. This is all auto-generated so I have not changed anything.</p>
  
  <pre><code>@model Dyad.GreenvilleFoodTrucks.Data.Location
  
  @{
  ViewBag.Title = "Create";
  }
  
  &lt;h2&gt;Create&lt;/h2&gt;
  
  
  @using (Html.BeginForm()) 
  {
  @Html.AntiForgeryToken()
  
  &lt;div class="form-horizontal"&gt;
      &lt;h4&gt;Location&lt;/h4&gt;
      &lt;hr /&gt;
      @Html.ValidationSummary(true, "", new { @class = "text-danger" })
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.TruckID, "TruckID", htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.DropDownList("TruckID", null, htmlAttributes: new { @class = "form-control" })
              @Html.ValidationMessageFor(model =&gt; model.TruckID, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.StartTime, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.StartTime, new { htmlAttributes = new { @class = "form-control" } })
              @Html.ValidationMessageFor(model =&gt; model.StartTime, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.EndTime, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.EndTime, new { htmlAttributes = new { @class = "form-control" } })
              @Html.ValidationMessageFor(model =&gt; model.EndTime, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Date, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.Date, new { htmlAttributes = new { @class = "form-control" } })
              @Html.ValidationMessageFor(model =&gt; model.Date, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Description, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.Description, new { htmlAttributes = new { @class = "form-control" } })
              @Html.ValidationMessageFor(model =&gt; model.Description, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Address, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.Address, new { htmlAttributes = new { @class = "form-control" } })
              @Html.ValidationMessageFor(model =&gt; model.Address, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.State, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.State, new { htmlAttributes = new { @class = "form-control" } })
              @Html.ValidationMessageFor(model =&gt; model.State, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.ZIP, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.ZIP, new { htmlAttributes = new { @class = "form-control" } })
              @Html.ValidationMessageFor(model =&gt; model.ZIP, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          &lt;div class="col-md-offset-2 col-md-10"&gt;
              &lt;input type="submit" value="Create" class="btn btn-default" /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  }
  
  &lt;div&gt;
  @Html.ActionLink("Back to List", "Index")
  &lt;/div&gt;
  
  @section Scripts {
  @Scripts.Render("~/bundles/jqueryval")
  }
  </code></pre>
  
  <p>And its controller:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Data;
  using System.Data.Entity;
  using System.Linq;
  using System.Net;
  using System.Web;
  using System.Web.Mvc;
  using Dyad.GreenvilleFoodTrucks.Data;
  
  namespace Dyad.GreenvilleFoodTrucks.Controllers
  {
  public class LocationsController : Controller
  {
      private GreenvilleFoodTrucksEntities db = new GreenvilleFoodTrucksEntities();
  
      // GET: Locations
      public ActionResult Index()
      {
          var locations = db.Locations.Include(l =&gt; l.Truck);
          return View(locations.ToList());
      }
  
      // GET: Locations/Details/5
      public ActionResult Details(int? id)
      {
          if (id == null)
          {
              return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
          }
          Location location = db.Locations.Find(id);
          if (location == null)
          {
              return HttpNotFound();
          }
          return View(location);
      }
  
      // GET: Locations/Create
      public ActionResult Create()
      {
          ViewBag.TruckID = new SelectList(db.Trucks, "ID", "Name");
          return View();
      }
  
      // POST: Locations/Create
      // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
      // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
      [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Create([Bind(Include = "ID,TruckID,StartTime,EndTime,Date,Description,Address,State,ZIP")] Location location)
      {
          if (ModelState.IsValid)
          {
              db.Locations.Add(location);
              db.SaveChanges();
              return RedirectToAction("Index");
          }
  
          ViewBag.TruckID = new SelectList(db.Trucks, "ID", "Name", location.TruckID);
          return View(location);
      }
  
      // GET: Locations/Edit/5
      public ActionResult Edit(int? id)
      {
          if (id == null)
          {
              return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
          }
          Location location = db.Locations.Find(id);
          if (location == null)
          {
              return HttpNotFound();
          }
          ViewBag.TruckID = new SelectList(db.Trucks, "ID", "Name", location.TruckID);
          return View(location);
      }
  
      // POST: Locations/Edit/5
      // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
      // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
      [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Edit([Bind(Include = "ID,TruckID,StartTime,EndTime,Date,Description,Address,State,ZIP")] Location location)
      {
          if (ModelState.IsValid)
          {
              db.Entry(location).State = EntityState.Modified;
              db.SaveChanges();
              return RedirectToAction("Index");
          }
          ViewBag.TruckID = new SelectList(db.Trucks, "ID", "Name", location.TruckID);
          return View(location);
      }
  
      // GET: Locations/Delete/5
      public ActionResult Delete(int? id)
      {
          if (id == null)
          {
              return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
          }
          Location location = db.Locations.Find(id);
          if (location == null)
          {
              return HttpNotFound();
          }
          return View(location);
      }
  
      // POST: Locations/Delete/5
      [HttpPost, ActionName("Delete")]
      [ValidateAntiForgeryToken]
      public ActionResult DeleteConfirmed(int id)
      {
          Location location = db.Locations.Find(id);
          db.Locations.Remove(location);
          db.SaveChanges();
          return RedirectToAction("Index");
      }
  
      protected override void Dispose(bool disposing)
      {
          if (disposing)
          {
              db.Dispose();
          }
          base.Dispose(disposing);
      }
  }
  }
  </code></pre>
  
  <p>With all this addressed, I would also like to point that none of this happens when I run VS as admin, which I do not understand. Also, every compiles and runs as usual.</p>
  
  <p>I apologize for the lengthy write-up, but I didn't want to leave anything out. I also apologize if I misused any terms as I am fairly new to MVC and C# in general.</p>
  
  <p>If there is anything else I can include please let me know.</p>