3
votes

If I create a new project in VS2010 and add ServiceStack by following these simple steps... I get a project that won't build and I can't figure out what to do... from Googling it seems like it might have something to do with the Web.config... but it's beyond me. Any help?

Visual Studio 2010
File -> New -> Website… ASP.NET Website (Razor)
Compile no problem
right click on project -> Manage NuGet Packages
Search for "ServiceStack.Razor"
Found 1 item and click Install
Rebuild All and I get about 8 of these errors:
Error 1 The namespace 'Razor' already contains a definition for '__CompiledTemplate' c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\backend\6f939f81\a07fd23c\App_Web_rw2opozl.3.cs 15
Error 2 The namespace 'Razor' already contains a definition for '__CompiledTemplate' c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\backend\6f939f81\a07fd23c\App_Web_rw2opozl.0.cs 15
etc…

Web.config file:

<?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=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <system.web>
    <compilation debug="true" targetFramework="4.0"><assemblies>
        <add assembly="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies><buildProviders>
        <add extension=".cshtml" type="ServiceStack.Razor.CSharpRazorBuildProvider, ServiceStack.Razor" />
      </buildProviders></compilation>
  </system.web>

  <connectionStrings>
    <add name="StarterSite" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\StarterSite.mdf;User instance=true" providerName="System.Data.SqlClient" />
  </connectionStrings>
<appSettings>
    <add key="webPages:Enabled" value="false" />
  </appSettings><system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="ServiceStack.Razor.ViewPage">
      <namespaces>
        <add namespace="ServiceStack.Html" />
        <add namespace="ServiceStack.Razor" />
        <add namespace="ServiceStack.Text" />
        <add namespace="ServiceStack.OrmLite" />
        <add namespace="ASP" />
      </namespaces>
    </pages>
  </system.web.webPages.razor></configuration>
1
This also happens with VS2012.Brian Rice

1 Answers

2
votes

I never was able get this to work... I ended up taking the Rockstars example and deleting and replacing stuff... until I had what I wanted... but here are a few gotchas...

For debugging this was needed in the Web.Config:

  <system.web>
    <httpHandlers>
      <add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" />
    </httpHandlers>
  </system.web>

For production this was needed:

  <system.webServer>
    <handlers>
      <add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true"/>
    </handlers>
  </system.webServer>

The NuGet put both in there (I think) which worked when debugging, but didn't work in production.

Also NuGet ended up with this in the Web.Config:

  <appSettings>
    <add key="webPages:Enabled" value="false" />
    <add key="webPages:Enabled" value="true" />
  </appSettings>

I deleted the one that was true (this was what was giving me the "__CompiledTemplate" error).