Antaris / RazorEngine

Open source templating engine based on Microsoft's Razor parsing engine
http://antaris.github.io/RazorEngine
Other
2.14k stars 577 forks source link

FileNotFoundException when compiling templates #525

Open gjdownes opened 6 years ago

gjdownes commented 6 years ago

Hi there,

I'm periodically running into the following issue. When I call the Compile method:

System.IO.FileNotFoundException: Could not find file 'C:\Windows\TEMP\RazorEngine_lfwzmkby.hyf\CompiledRazorTemplates.Dynamic.RazorEngine_cae87e534dd3478997ea489146bac6fa.dll'

This seems to happen with certain templates, not all. I'm looking for any guidance as to what may be the issue here. Is it possible the cache is being cleared out prematurely?

var engine = RazorEngineContext.Current.RazorEngine;
if (!engine.IsTemplateCached (templateKey, modelType))
    engine.Compile (templateSource, templateKey, modelType);

return engine.Run (templateKey, modelType, model).Trim ();

Full stack trace below:

File name: 'C:\Windows\TEMP\RazorEngine_lfwzmkby.hyf\CompiledRazorTemplates.Dynamic.RazorEngine_cae87e534dd3478997ea489146bac6fa.dll' at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.File.InternalReadAllBytes(String path, Boolean checkHost) at RazorEngine.Compilation.DirectCompilerServiceBase.CompileTypeImpl(TypeContext context) at RazorEngine.Compilation.DirectCompilerServiceBase.CompileType_Windows(TypeContext context) at RazorEngine.Compilation.DirectCompilerServiceBase.CompileType(TypeContext context) at RazorEngine.Templating.RazorEngineCore.CreateTemplateType(ITemplateSource razorTemplate, Type modelType) at RazorEngine.Templating.RazorEngineCore.Compile(ITemplateKey key, Type modelType) at RazorEngine.Templating.RazorEngineService.CompileAndCacheInternal(ITemplateKey key, Type modelType) at RazorEngine.Templating.RazorEngineService.Compile(ITemplateKey key, Type modelType) at RazorEngine.Templating.DynamicWrapperService.Compile(ITemplateKey key, Type modelType)

gjdownes commented 6 years ago

Seems like restarting the box fixed this issue, but I'm still curious as to why or how this could happen. Based on my observations the folder/.dll was created in windows/temp and immediately deleted...

IanYates commented 6 years ago

I had a very similar issue in production. Changing permissions, identity of app pool, etc didn't fix it. A restart of the Windows server did the trick though. First time hitting it in a couple of years so I won't lose too much sleep over it yet :)

azmodii commented 4 years ago

+1. Currently experiencing this issue. Restarting daily. Seems to have something to do with the volume of pages processed.