ServiceStack/ServiceStack — pull request #865 by Its-Tyson (2013-12-01 03:21:12+00:00)
Title: Razor fixes and precompile

I started by just trying to fix intermittent errors I get on AppHarbor to do with razor compilation:

Sat Nov 30 04:01:35.7000 +00:00 2013 HttpResponseExtensions : Error, Error occured while Processing Request: [InvalidOperationException] The output writer for code generation and the writer supplied don't match and cannot be used. This is generally caused by a bad implementation of a CodeGenerator derived class., System.InvalidOperationException: The output writer for code generation and the writer supplied don't match and cannot be used. This is generally caused by a bad implementation of a CodeGenerator derived class.
at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeGenerator.GenerateCodeFromCompileUnit(CodeCompileUnit e, TextWriter w, CodeGeneratorOptions o)
at Microsoft.CSharp.CSharpCodeGenerator.FromDomBatch(CompilerParameters options, CodeCompileUnit[] ea)
at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromDomBatch(CompilerParameters options, CodeCompileUnit[] ea)
at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromDom(CompilerParameters options, CodeCompileUnit[] compilationUnits)
at ServiceStack.Razor.Compilation.RazorPageHost.Compile()
at ServiceStack.Razor.Managers.RazorPageResolver.EnsureCompiled(RazorPage page, IHttpResponse response)
at ServiceStack.Razor.Managers.RazorPageResolver.CreateRazorPageInstance(IHttpRequest httpReq, IHttpResponse httpRes, Object dto, RazorPage razorPage)
at ServiceStack.Razor.Managers.RazorPageResolver.ResolveAndExecuteRazorPage(IHttpRequest httpReq, IHttpResponse httpRes, Object model, RazorPage razorPage)
at ServiceStack.Razor.Managers.RazorPageResolver.ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, Object dto)
at ServiceStack.WebHost.Endpoints.Formats.HtmlFormat.<>c__DisplayClass1.b__0(IViewEngine x)
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
at ServiceStack.WebHost.Endpoints.Formats.HtmlFormat.SerializeToStream(IRequestContext requestContext, Object response, IHttpResponse httpRes)
at ServiceStack.Common.Web.HttpResponseFilter.SerializeToStream(IRequestContext requestContext, Object response, Stream responseStream)
at ServiceStack.Common.Web.HttpResult.WriteTo(Stream responseStream)
at ServiceStack.WebHost.Endpoints.Extensions.HttpResponseExtensions.WriteToOutputStream(IHttpResponse response, Object result, Byte[] bodyPrefix, Byte[] bodySuffix)
at ServiceStack.WebHost.Endpoints.Extensions.HttpResponseExtensions.WriteToResponse(IHttpResponse response, Object result, ResponseSerializerDelegate defaultAction, IRequestContext serializerCtx, Byte[] bodyPrefix, Byte[] bodySuffix)

However after fixing the issue, realized precompilation wouldn't be too much work so added that too.

I do remember seeing existing precompilation code somewhere but couldn't find any reference of it in the Razor functionality. Let me know if I duplicated anything and I can refactor.