6

This is the weirdest error I have ever encountered.

This MVC web project was working fine until today. It hasn't been worked on by anyone in a couple of weeks.

Even though NOTHING has changed, simply running it now results in:

The type or namespace name 'ColourboxViewModel' does not exist in the namespace 'CMSModels.ViewModels'

(x5)

The type or namespace name 'Colourbox' does not exist in the namespace 'CMSModels' (are you missing an assembly reference?)

(x1)

There is a reference to CMSModels in the project. Removing this reference gives me about 200 extra errors for each other class in the namespace, so I know it is working, but not for these two errors.

This is the line of generated code which the error points to:

public class views_colorbox_index_aspx : System.Web.Mvc.ViewPage<IEnumerable<CMSModels.Colourbox>>, System.Web.SessionState.IRequiresSessionState, System.Web.IHttpHandler {
...
public class views_colorbox_content_ascx : System.Web.Mvc.ViewUserControl<CMSModels.ViewModels.ColourboxViewModel> {

Intellisense is picking up the location of both CMSModels.ColourBox and CMSModels.ViewModels.ColourboxViewModel.

I am completely stumped. Any help greatly appreciated as I am completely at a loss.


OK I have found the issue - but not the solution.

The class is defined as

public class ColourBoxViewModel

yet the generated code is looking for a class of 'ColourboxViewModel'. Note the lowercase B. Where does the auto-gen code get the names of classes from? Search in project reveals no mentions of it with a lowercase b.

The issue is the same for the ColourBox class.


Problem solved - and @František Žiačik you were correct. There was a folder which had been excluded from the project (which is why searching in entire project and within the views in visual studio found nothing) which contained the incorrectly typed inherit statement. The excluded folder was called ColorBox when originally created by outsourcers. This had been copied and renamed as ColourBox by another dev on the team who decided to, and I quote, 'spell everything correctly'. Said dev is now only allowed to code using a Speak n' Spell.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • This could be a ReSharper bug. I came it across a couple times. Like SLaks said try to clean, re-build and build your solution. If this doesn`t help and you`re using TFS, you can try to close your solution and get latest on your project again from soruce control. – cordellcp3 Apr 05 '11 at 13:41
  • Rebuilding resulted in the same error. We use SVN for version control, however getting a new copy of the project from the repository results in the same issue. – Rory McCrossan Apr 05 '11 at 14:09
  • Could that be a typo in case of the `B` character in `ColourboxViewModel` in your error vs `ColourBoxViewModel` in class definition? – František Žiačik Apr 05 '11 at 14:30
  • It's definitely not a typo unfortunately. Here is a screenshot showing the generated code, and my class. http://i470.photobucket.com/albums/rr70/RoryMK/vsgencode-error.gif – Rory McCrossan Apr 05 '11 at 14:44
  • I still can see on the screenshot that the class is typed with `B` and is used with `b` in ascx. It can't work that way. The question is, if it is a generated class, where did it get the lowercase name from. – František Žiačik Apr 05 '11 at 14:52
  • I guess you have it declared that way somewhere in the ascx directives at start. – František Žiačik Apr 05 '11 at 14:54

2 Answers2

5

I had this error yesterday, and I found these answers, but in my case they didn't help. Instead it turned out that in my client in project properties the Target framework was set to .NET Framework 4 Client Profile. Solution was to change this to full .NET 4. Hope this can help someone, because the error in VS is not very helpfull.

JerryA
  • 153
  • 1
  • 8
5

So here is my guess.

In your content.ascx view (or whatever it's named) you have declared:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CMSModels.ViewModels.ColourboxViewModel>" %>

instead of

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CMSModels.ViewModels.ColourBoxViewModel>" %>
František Žiačik
  • 7,511
  • 1
  • 34
  • 59
  • 5
    Hmm...Can you help those of us too dumb to spot the difference? – Justin Morgan - On strike Apr 05 '11 at 15:02
  • This was my first thought but I can guarantee that all pages and controls inheriting this class use ColourBoxViewModel. – Rory McCrossan Apr 05 '11 at 15:04
  • 1
    Problem solved - and @František Žiačik you were correct. There was a folder which had been excluded from the project (which is why searching in entire project and within the views in visual studio found nothing) which contained the incorrectly typed inherit statement. The excluded folder was called ColorBox when originally created by outsourcers. This had been copied and renamed as ColourBox by another dev on the team who decided to, and I quote, 'spell everything correctly'. Said dev is now only allowed to code using a Speak n' Spell. – Rory McCrossan Apr 05 '11 at 15:20
  • 1
    @RoryMcCrossan My gift to you for making me chuckle after reading your comment: https://i.imgur.com/gKIrSil.png – lance May 05 '14 at 20:11