MVC5 with VB.NET: "BC30451:" ViewData "not declared." when switching to Debug configuration

I have an MVC5 project that is currently installed in Release Configuration, and it works 100%. However, as soon as I switch the project configuration from Release to Debug, everything goes wrong ... even if I switch it back to Release mode, everything will still break. The only way to get the project to work again is to restore it from backup.

This is what happens. Firstly, when I start a project, I get the following error:

BC30451: 'ViewData' not declared. It may not be available due to its level of protection.

If I open any view in the project using Visual Studio 2013, I see that all views are flagged as errors, such as ViewData, Html, Url, etc.

When you refer to @Html or @ViewData in a view, it usually refers to the .Html and .ViewData properties of the view base class (WebViewPage). However, if I start typing "@Html". in any of the views, I can see in autocomplete that this refers to the System.Web.Webpages.Html namespace, and not to the WebViewPage.Html property. This is so: if the view does not inherit from the System.Web.Mvc.WebViewPage class.

Any guidance on where I can start looking for this fix, or why is this happening?

Edit Since no one answered, I have come a long way. I created a new MVC5 project, added all the packages through Nuget, and then just copied all my files from the old project to the new one, and now it works.

Can anyone understand what could be causing this? I do not want to repeat all these problems in the future if the project suddenly decides to stop working again.

+8
asp.net-mvc asp.net-mvc-5
source share
3 answers

Well, I think I found part of the reason here. The fact is, since the source code is valid (it compiles correctly, and intellisense selects it) and the code used to work, and then suddenly, a day after compilation, it just stops working.

Anyway, in the view, when you specify ModelType, if you do not use the full name, this error may or may eventually occur. For example, using:

@ModelType Models.SomeNamespace.SomeClass 

will result in an error (although the root namespace for the project is "MyProject"), and it can be fixed simply by specifying the full namespace and class name.

 @ModelType MyProject.Models.SomeNamespace.SomeClass 
+1
source share

Perhaps the debug lock is locked. You can close Visual Studio, search, and delete all bin folders in the solution directory. Then open and rebuild.

Other options are to go to the properties of the MVC project and compare two build configurations. Have you targeted another .NET platform between Release and Debug? 32 bit vs 64 bit? etc.?

+1
source share

It looks like some MVC builds are corrupted. Have you checked your referenced builds for errors?

Try also flushing the entire internal .NET cache. More on this topic stackoverflow: Failed to load file or assembly ... Invalid parameter

+1
source share

All Articles