ServiceStack Razor views not compiling

I successfully implement Razor Viewpages in a self-employed service, the pages are displayed fine until I update to 3.9.56. Views were tested in a Windows forms application along with a Windows Forms client that will handle json responses from the service. This still works fine, but now when I test Razor Views, I leave the following exception when requesting the page:

ERROR: Error occured while Processing Request: [HttpCompileException] c:\Users\Cornel\AppData\Local\Temp\2msjdedu.0.cs(24): error CS0246: The type or namespace name 'ViewPage' could not be found (are you missing a using directive or an assembly reference?), Exception: c:\Users\Cornel\AppData\Local\Temp\2msjdedu.0.cs(24): error CS0246: The type or namespace name 'ViewPage' could not be found (are you missing a using directive or an assembly reference?)

I built a small console application to host the service and Razor Views, and the pages are correct. Both projects have the same links, with the exception of links to the Windows Forms build on the testing platform. Both projects run AppHost from the same management class in a separate assembly, and all views have been published.

The only difference in the configuration file is the <userSettings> section of the Windows Forms test environment.

[change]

When I change @inherits ViewPage to @inherits ServiceStack.Razor.ViewPage everything works as expected

+6
source share
1 answer

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", }); 
+6
source

Source: https://habr.com/ru/post/950873/


All Articles