Antaris / RazorEngine

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

System.Runtime.Serialization.SerializationException when doing clean up method called #293

Open chamchu opened 9 years ago

chamchu commented 9 years ago

We've started running into this issue when Razor Engine attempts to do what looks like a cleanup:

Type is not resolved for member 'RazorEngine.Compilation.CrossAppDomainCleanUp+ErrorOnlyPrinter,RazorEngine, Version=3.7.0.0, Culture=neutral, PublicKeyToken=9ee6...

Inner: at RazorEngine.Compilation.CrossAppDomainCleanUp.CleanupHelper.Init(AppDomain domain, IPrinter printer) at RazorEngine.Compilation.CrossAppDomainCleanUp.InitHelper.CreateHelper() at RazorEngine.Compilation.ExecutionContextLessThread.CallHelperSafeHelper2.AsAction() at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at RazorEngine.Compilation.ExecutionContextLessThread.DefaultCallFunc[O](Func1 f) at RazorEngine.Compilation.CrossAppDomainCleanUp..ctor(AppDomain toWatch, IPrinter printer) at RazorEngine.Compilation.CrossAppDomainCleanUp.CreateInitial() at System.Lazy`1.CreateValue()

--- End of stack trace from previous location where exception was thrown ---

at System.Lazy1.get_Value() at RazorEngine.Compilation.CrossAppDomainCleanUp.RegisterCleanup(String item, Boolean throwOnDefault) at RazorEngine.Templating.InvalidatingCachingProvider.CacheTemplate(ICompiledTemplate template, ITemplateKey templateKey) at RazorEngine.Templating.RazorEngineService.CompileAndCacheInternal(ITemplateKey key, Type modelType) at RazorEngine.Templating.RazorEngineService.GetCompiledTemplate(ITemplateKey key, Type modelType, Boolean compileOnCacheMiss) at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag) at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass4.<RunCompile>b__3(TextWriter writer) at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action1 withWriter)

This happens intermittently and haven't had luck reproducing it. We upgraded from 3.3.00 to Razor Engine 3.7.0.0 stable release. Wasn't an issue prior to the upgrade.

matthid commented 9 years ago

Without repro I cannot track it down, sorry. Can you provide the code that reproduces this problem (maybe privately)? How easy is it to trigger this?

fireflystorm commented 9 years ago

Hi. I am experiencing exactly the same issue. An intermitten exception is thrown and I can't seem to do anything until I restart the website. @chamchu how did you resolve your issue? My situation I am using RazorEngine on its own(ie not part of an MVC app) to compile email templates. It works fine but after some hours I start getting the above error whenever I try to compile a template

matthid commented 8 years ago

Workaround is

var config = new TemplateServiceConfiguration();
config.CachingProvider = new DefaultCachingProvider(t => { });
config.DisableTempFileLocking = true;
Engine.Razor = RazorEngineService.Create(config);

but again, a repro would be appreciated...