This problem drove me crazy. I just found a solution: app.config a ServiceStack.Razor application contains a section like this:
<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="System.Linq" /> <add namespace="ServiceStack.Html" /> <add namespace="ServiceStack.Razor" /> <add namespace="ServiceStack.Text" /> <add namespace="ServiceStack.OrmLite" /> <add namespace="MyApp" /> <add namespace="MyApp.Services" /> </namespaces> </pages> </system.web.webPages.razor>
This is the import of default names for all Razor templates. The problem occurs when the application is in a separate DLL, for example, it looks like your example. Let's say you have a console application project called MyApp.Host that references MyApp . Instead of looking for the default import in MyApp.Host.exe.config , ServiceStack looks for them in the DLL configuration file containing AppHost, in this case MyApp.dll.config . The problem is that this configuration file is not automatically copied to the bin folder of MyApp.Host upon creation.
The solution is relatively simple: add something similar to the following in the MyApp.Host post-build MyApp.Host :
copy /y $(SolutionDir)MyApp\app.config $(TargetDir)MyApp.dll.config
Edit: You can also add import programmatically (see Getting the HttpCompileException in the Razor ServiceStack (Self hosting) view ):
EndpointHostConfig.RazorNamespaces.Add("ServiceStack.Razor"); EndpointHostConfig.RazorNamespaces.Add("MyApp"); EndpointHostConfig.RazorNamespaces.Add("MyApp.Services"); SetConfig(new EndpointHostConfig { DefaultRedirectPath = "/Home", });
source share