ASP.NET MVC 3 Type ‘xxx.xxx’ could not be found.

Here’s a strange little error that I can’t, for some reason, get to the bottom of. My code is reasonably standard and working perfectly on my development machine. When I deploy to an IIS6 box that I’ve set up to work with ASP.NET MVC 3, I keep getting

Type ‘xxx.xxx’ could not be found. Make sure that the required schemas are loaded and that the namespaces are imported correctly

The error is strange – it only seems to happen when I have slightly more complicated logic in my controller. I had my dbcontext in its own namespace and since this was the namespace that seemed to be referenced in the error, the fix for me was to move my dbcontext out of its own namespace and put it in the Models namespace. Not super neat and tidy, but it works.