Contact   •   Products   •   Search

Rick Strahl's Web Log

Wind, waves, code and everything in between...
ASP.NET • C# • HTML5 • JavaScript • AngularJs

Odd MVC 4 Beta Razor Designer Issue


This post is a small cry for help along with an explanation of a problem that is hard to describe on twitter or even a connect bug and written in hopes somebody has seen this before and any ideas on what might cause this. Lots of helpful people had comments on Twitter for me, but they all assumed that the code doesn't run, which is not the case - it's a designer issue.

A few days ago I started getting some odd problems in my MVC 4 designer for an app I've been working on for the past 2 weeks. Basically the MVC 4 Razor designer keeps popping me errors, about the call signature to various Html Helper methods being incorrect. It also complains about the ViewBag object and not supporting dynamic requesting to load assemblies into the project.

Here's what the designer errors look like:

MVC Errors

You can see the red error underlines under the ViewBag and an Html Helper I plopped in at the top to demonstrate the behavior. Basically any HtmlHelper I'm accessing is showing the same errors.

Note that the code *runs just fine* - it's just the designer that is complaining with Errors.

What's odd about this is that *I think* this started only a few days ago and nothing consequential that I can think of has happened to the project or overall installations. These errors aren't critical since the code runs but pretty annoying especially if you're building and have .csHtml files open in Visual Studio mixing these fake errors with real compiler errors.

What I've checked

Looking at the errors it indeed looks like certain references are missing. I can't make sense of the Html Helpers error, but certainly the ViewBag dynamic error looks like System.Core or Microsoft.CSharp assemblies are missing. Rest assured they are there and the code DOES run just fine at runtime. This is a designer issue only.

I went ahead and checked the namespaces that MVC has access to in Razor which lives in the Views folder's web.config file:

/Views/web.config

For good measure I added

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc,  <split for layout>
Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35
" /> <pages pageBaseType="System.Web.Mvc.WebViewPage"> <namespaces> <add namespace="System.Web.Mvc" /> <add namespace="System.Web.Mvc.Ajax" /> <add namespace="System.Web.Mvc.Html" /> <add namespace="System.Web.Routing" /> <add namespace="System.Linq" /> <add namespace="System.Linq.Expressions" /> <add namespace="ClassifiedsBusiness" /> <add namespace="ClassifiedsWeb"/> <add namespace="Westwind.Utilities" /> <add namespace="Westwind.Web" /> <add namespace="Westwind.Web.Mvc" /> </namespaces> </pages> </system.web.webPages.razor>

For good measure I added System.Linq and System.Linq.Expression on which some of the Html.xxxxFor() methods rely, but no luck.

So, has anybody seen this before? Any ideas on what might be causing these issues only at design time rather, when the final compiled code runs just fine?

Make Donation
Posted in Razor  MVC  


Feedback for this Post

 
# re: Odd MVC 4 Beta Razor Designer Issue
by Jeff Putz April 14, 2012 @ 4:27pm
I've seen it, and it seemed to clear up restarting VS. ReSharper Intellisense seems to stop it too.

I don't know if it's in the tooling or the library, but if it's the latter, I'd post an issue on CodePlex, not Connect.
# re: Odd MVC 4 Beta Razor Designer Issue
by Peter April 14, 2012 @ 7:00pm
I've seen something similar; to fix it I had to close VS and manually delete the temp files. I don't remember exactly which folders I cleaned, but I think it was these:

C:\Users\Peter\AppData\Local\Microsoft\WebsiteCache\
C:\Users\Peter\AppData\Local\Temp\Temporary ASP.NET Files\
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\

I hope this helps.
# re: Odd MVC 4 Beta Razor Designer Issue
by Maurice April 14, 2012 @ 11:52pm
Sounds like it's possibly the same problem I ran into with MVC3. See this blog post https://msmvps.com/blogs/theproblemsolver/archive/2012/03/14/installing-asp-net-mvc-4-beta-breaks-asp-net-mvc-3-rtm-applications.aspx

It seems that VS2010 loaded a WebPages DLL instead of the required MVC one at design time.

In my case "C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.WebPages.dll" instead of " C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll" even though the ;ast was was the one the project referenced.
# re: Odd MVC 4 Beta Razor Designer Issue
by Athson Wang January 21, 2013 @ 1:02am
Hi, I happened the same issue, and just occasionally solve this problem. I don't know if we have the same situations, but hope will help to you. In my case, I using ”Blend for Visual Studio 2012“ open the project(a ASP.NET MVC 4 project), then I found a temporary folder(like this: {5542434-2...5323}, named by GUID, maybe?), please delete it.

Thanks.
-- Athson.
 


West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2014