Project Difficulty with Razor in 5.0.0 (.Net Framework)

Hello,

I’m working on an old project which uses ServiceStack 5.0.0. in an ASP.Net Framework (4.7.2) project.

For some reason visual studio produces error messages like this:

The errors read like this: CS0234: The type or namespace name 'WebPages' does not exist...

Other than displaying errors in the IDE the software seems to run correctly in debug and in production.

Our packages file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AngularJS.Core" version="1.8.0" targetFramework="net472" />
<package id="AngularJS.Messages" version="1.8.0" targetFramework="net472" />
<package id="AngularJS.Route" version="1.8.0" targetFramework="net472" />
<package id="Elasticsearch.Net" version="7.10.1" targetFramework="net472" />
<package id="jQuery" version="2.2.2" targetFramework="net472" />
<package id="materialize" version="0.97.6" targetFramework="net472" />
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net472" />
<package id="Microsoft.CSharp" version="4.6.0" targetFramework="net472" />
<package id="NEST" version="7.10.1" targetFramework="net472" />
<package id="NEST.JsonNetSerializer" version="7.10.1" targetFramework="net472" />
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net472" />
<package id="ServiceStack" version="5.0.0" targetFramework="net472" />
<package id="ServiceStack.Client" version="5.0.0" targetFramework="net472" />
<package id="ServiceStack.Common" version="5.0.0" targetFramework="net472" />
<package id="ServiceStack.Interfaces" version="5.0.0" targetFramework="net472" />
<package id="ServiceStack.OrmLite" version="5.0.0" targetFramework="net472" />
<package id="ServiceStack.Razor" version="5.0.0" targetFramework="net472" />
<package id="ServiceStack.Redis" version="5.0.0" targetFramework="net472" />
<package id="ServiceStack.Server" version="5.0.0" targetFramework="net472" />
<package id="ServiceStack.Text" version="5.0.0" targetFramework="net472" />
<package id="System.Buffers" version="4.5.1" targetFramework="net472" />
<package id="System.Diagnostics.DiagnosticSource" version="5.0.0" targetFramework="net472" />
<package id="System.Memory" version="4.5.4" targetFramework="net472" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
<package id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" targetFramework="net472" />
</packages>

Our web.config includes the following relevant sections:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false"/>
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false"/>
</sectionGroup>
</configSections>
<system.web>
<compilation targetFramework="4.7.2" debug="true">
<assemblies>
<add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"/>
</assemblies>
<buildProviders>
<add extension=".cshtml" type="ServiceStack.Razor.CSharpRazorBuildProvider, ServiceStack.Razor"/>
</buildProviders>
</compilation>
<httpRuntime requestPathInvalidCharacters="" targetFramework="4.5" maxRequestLength="500000000"/>
<httpHandlers>
<add path="*" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*"/>
</httpHandlers>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<urlCompression doStaticCompression="true" doDynamicCompression="false"/>
<handlers>
<add path="*" name="ServiceStack.Factory" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true"/>
<remove name="WebDAV"/>
</handlers>
<modules>
<remove name="WebDAVModule"/>
</modules>
</system.webServer>
<appSettings>
<add key="webPages:Enabled" value="false"/>
</appSettings>
<system.web.webPages.razor>
<pages pageBaseType="ServiceStack.Razor.ViewPage">
<namespaces>
<add namespace="MediaDetectionFrontend.ServiceModel"/> <!-- My application -->
<add namespace="System"/>
<add namespace="System.Linq"/>
<add namespace="ServiceStack"/>
<add namespace="ServiceStack.Html"/>
<add namespace="ServiceStack.Razor"/>
<add namespace="ServiceStack.Text"/>
<add namespace="ServiceStack.OrmLite"/>
<add namespace="MediaDetectionFrontend"/> <!-- My application -->
</namespaces>
</pages>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</system.web.webPages.razor>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

Our use-case involves an public class SecuredViewPage : ViewPageBase<dynamic>, IRazorView from which the default view is derived. This code is in /App_Code/SecuredViewPage.cs

Any idea what’s going wrong here?

I thought this would be a matter of adding relevant namespaces in the system.web.webPages.razor config, but that doesn’t seem to make any difference. Many thanks!

Are these only design time errors in VS.NET, i.e. the Razor pages still get executed?

We don’t have much control over VS .NET designer errors, but our guidance to reduce the number of warnings is documented here:

https://docs.servicestack.net/razor-notes

e.g. add a dependency to Microsoft.AspNet.WebPages if you haven’t already.