Razor ServiceModel Namespace doesn't exist

Maybe I’m missing something that was introduced in 4.5.6, but we’re not sure what is going on here. We do not have a namespace of ServiceModel in our code however ServiceModel seems to be added in the precompiled SS Razor Views for every view (359+ errors). Upgraded from 4.0.39 to 4.5.7 (Mar 23).

using MyCompany.MyWebsite.ServiceModel

Why is ServiceModel being added to the precompiled views?

Error 1 The type or namespace name ‘ServiceModel’ does not exist in the namespace ‘MyCompany.MyWebsite’ (are you missing an assembly reference?) C:\dev\MySolution\src\MyCompany.MyWebsite\obj\Debug\MyCompany.MyWebsite.Views.Shared._Layout.cshtml.g.cs 22 29 MyCompany.MyWebsite

Razor Code Generated Gist

The ServiceModel is a core project in our Physical Project Structure that’s embedded in all ServiceStackVS VS.NET Templates. It’s a fundamental concept in ServiceStack that all your DTOs are maintained in a separate dependency-free ServiceModel project, the convention for this namespace is {ProjectName}.ServiceModel and it’s expected that all ServiceStack projects have one.

The Razor namespaces in Web.config is used to control which namespaces should be added in Razor Views, so you should be able to remove namespaces you aren’t using from there.

This is going to make upgrading more difficult as it wasn’t this way before. Probably going to rethink this upgrade now until a later date…

The problem is none of our models are in our website projects which is what is added in the generated razor pages using MyCompany.MyWebsite.ServiceModel;. We have 4 website projects and 1 core project that contains all of our service models that the web projects reference. There is no need to separate the models into each MyWebsite namespace as it would duplicate every model just about.

Core Project:
MyCompany.Models
MyCompany.Services

Website Project 1:
MyCompany.MyWebsite1

Website Project 2:
MyCompany.MyWebsite2

Website Project 3:
MyCompany.MyWebsite3

Website Project 4:
MyCompany.MyWebsite4

ok can’t you just remove the namespace from Razor Web.config? AFAIK this hasn’t changed in years. You may need to do a clean rebuild afterwards.

Ahhh didn’t see it. All those namespaces that were programmatically added in <system.web.webPages.razor> were added all on one looong line.

Also, the VS Find All in Solution wasn’t set to look into .config files. My bad. Compiles now. Thanks for the response! Your awesome!

1 Like