I am using Nancy and Razor together to build my web app. I am able to serve up Razor views, and they display totally fine. However, Visual Studio 2015 reports errors on almost every line in my .cshtml file, despite there being no run-time errors at all:
The specific errors that I have seen are:
- Predefined type 'System.Boolean' is not defined or imported
- Predefined type 'System.String' is not defined or imported
- The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
I believe that I have configured my app.config correctly, as per the documentation:
<?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=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
<section name="razor" type="Nancy.ViewEngines.Razor.RazorConfigurationSection, Nancy.ViewEngines.Razor" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<appSettings>
<add key="webPages:Enabled" value="false" />
</appSettings>
<system.web.webPages.razor>
<pages pageBaseType="Nancy.ViewEngines.Razor.NancyRazorViewBase">
<namespaces>
<add namespace="Nancy.ViewEngines.Razor" />
</namespaces>
</pages>
</system.web.webPages.razor>
<razor disableAutoIncludeModelNamespace="false">
<assemblies>
<add assembly="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add assembly="mscorlib , Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</razor>
<system.web>
<compilation>
<assemblies>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add assembly="mscorlib , Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
</configuration>
I believe however that the documentation might be a little out of date. It makes references to an ASP.NET MVC installer which I don't believe exists any more; I believe this is now built in to Visual Studio 2015.
I have tried writing all assemblies into /bin, as per this SO question, but this had no effect. I guess that something is missing from the Nancy documentation, and if someone would be kind enough to tell me what that is, I'll contribute it.