0

I recently updated our projects from .Net 4.0 to .Net 4.6 and decided to also update from MVC 4 to MVC 5. I updated all NuGet packages and all projects builds and compiles, but if I open any of the .cshtml files, I can see that ViewBag.Title is underlined with an error saying:

Error 1 One or more types required to compile a dynamic expression cannot be found. Are you missing a reference?



I also get another error (please note that the image below and error in the quote block below are related):

enter image description here

Error 2 The type arguments for method 'System.Web.Mvc.Html.SelectExtensions.DropDownListFor(System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression>, System.Collections.Generic.IEnumerable, string)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

The issue in the error above is that Html.DropDownListFor does not recognize the m parameter and thinks it is dynamic, which it is not. I have the @model CallStatisticsModel at the top of the .cshtml page. The quote block contains the full error description.

I am well aware that issues like these have been posted (and solved) before, and I have tried (the last 8 days) to get to a solution and testing out what worked for others, who had the same issues, but with no luck. What I have tried, includes:

  • Uninstalling and installing NuGet packages related to MVC, Razor and WebPages
  • Double checked and triple checked that version numbers in web.config and /Views/web.config are correct
  • Checked that the .csproj file for the .cshtml file in question are referencing the correct MVC, Razor and WebPages references
  • Followed this guide
  • Googled (a lot)
  • Tried rebuilding the project itself and the entire solution
  • Reopened Visual Studio (2013)

Any advice, comment, or point in the right direction would be much appreciated, as this has been a great issue for me for over a week now.

Thank you all in advance!

ACetin
  • 97
  • 7
  • 1
    I'd probably try creating a separate from scratch MVC5 project - just something very basic (probably just whatever you get scaffolded for you). When that works fine I'd try to copy/paste one controller's code and a view or two from your other project. Assuming it still works, I'd then compare the .sln file, packages and project files to try to see what's different. Not an answer, but that's the approach I'd take... – GPW Feb 19 '18 at 15:36
  • Would you do that in the same solution that contains the projects, or another solution? – ACetin Feb 19 '18 at 15:41
  • I'd go for a completely new solution given that you've spent a week on it. Completely clean slate in a different folder... – GPW Feb 19 '18 at 15:44
  • All right, thank you, I'll try it out! – ACetin Feb 19 '18 at 15:47

1 Answers1

0

This post made the errors and red underlines disappear in Visual Studio, even though Html.DropDownListFor still thinks the passed object is dynamic.

I will have to settle with this for now.

ACetin
  • 97
  • 7