Search code examples
c#.netrazorengine

RazorEngine parse throws Unable to compile


I'm trying to compile a razor file with this line

RazorEngine.Razor.Parse("Hello world");

But it just throws

base {System.Exception} = {"Unable to compile template. Source file 'C:\\Windows\\TEMP\\vlu4zahf.0.cs' could not be found\n\nOther compilation errors may have occurred. Check the Errors property for more information."}

And the error property looks like this:

[0] = {error CS2001: Source file 'C:\Windows\TEMP\vlu4zahf.0.cs' could not be found}
[1] = {warning CS2008: No source files specified}

So there is no good information.

I'm running .NET 4.0 and Razor Engine 3.2.0.0

Update 1

I have located the error to this line in the RazorEngine

Tuple.Create(
                compileResult.CompiledAssembly.GetType("CompiledRazorTemplates.Dynamic." + context.ClassName),
                compileResult.CompiledAssembly);

Solution

  • This is most likely a permissions issue for the user account compiling the razor file. Make sure it has all but full control permission on C:\Windows\Temp

    See here for background info: http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/85f9b330-a938-4afe-a615-db83085e52d2/