Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio MVC 5 shows errors but compiles and runs okay

I'm getting a rather strange error, which seems to have started when I updated several NUGET packages (including to MVC 5). In my "_Layout.cshtml" file, I now get the error messages that you can see in this picture (sorry, I'm too new to post it directly here yet).

See here for error

These are listed as errors, not warnings. Yet my build succeeds and the project runs, and as far as I can tell it works fine. I only see these errors when I have the "_Layout.cshtml" file open. It's acting as though it can't see "System.Web.Optimization". However, if I hover over the line, it will prompt me to insert that text and make it say:

@System.Web.Optimization.Styles.Render("~/Content/kendo/css")

instead of:

@Styles.Render("~/Content/kendo/css")

But I never had to explicitly spell this out before, and if I start a new project it doesn't require me to do so. Obviously, some part of my updates has caused this strange behavior (I assume it's related to a config setting somewhere, but I can't figure out what or where). I've checked both config files (the "project" one and the "views" one), and I'm pretty sure the issue must be there, but it's beyond my ability to see the problem. If this were a normal "class" file, it would be obvious that I was missing a "using" statement at the top, but that doesn't seem to apply here.

Can anyone point me to a solution, other than explicitly pointing to the full reference in the code as mentioned above? That just doesn't seem like it should be necessary, and I feel like I'd be skirting the issue by doing so.

like image 429
Starfleet Security Avatar asked Dec 07 '13 16:12

Starfleet Security


People also ask

Which is the best way to handle errors in. net?

You can handle default errors at the application level either by modifying your application's configuration or by adding an Application_Error handler in the Global. asax file of your application. You can handle default errors and HTTP errors by adding a customErrors section to the Web. config file.

How to solve ASP.NET error?

Default ASP.NET error messages show our ASP.NET version and framework, plus the exception type. To fix the problem: Set customErrors mode to RemoteOnly or Doing this displays more generic, nondescript error messages. Set the defaultRedirect attribute of the <customErrors> element to redirect the user to a new page.


1 Answers

The most likely cause of this issue is that the web.config in your Views folder(s) is/are broken. Upgrading the ASP.NET MVC 5 requires quite a few configuration changes that I am not certain the NuGet package manager does (or does well, I think it takes care of a few of these). Along with the MVC 5 .dll, many of the other related assemblies also need to be updated and the related references updated as well.

Take a look at the following tutorial and ensure you have completed EACH of the required steps. Then do a clean, rebuild and see if your issues are resolved.

I have found that it is sometimes better to have VS create a new MVC project, then look at and compare the web.configs (both application root as well as the views folder web.config) that it generates to your project's configuration files to ensure that you are not including namespaces that don't belong and all version numbers are correct.

like image 183
Tommy Avatar answered Oct 22 '22 06:10

Tommy