RazorEngine icon indicating copy to clipboard operation
RazorEngine copied to clipboard

Cannot call Engine.Razor.RunCompile twice in application

Open htatuan opened this issue 10 years ago • 2 comments

Hi all,

I have a problem when working with Razor Engine, I call the method Engine.Razor.RunCompile (needed parameters) in my MVC Web application. First time, It worked but the second times with the exception below (re-click on button to call the method ) :

An exception of type 'System.ObjectDisposedException' occurred in RazorEngine.dll but was not handled in user code Additional information: Safe handle has been closed

Anyone help me on this ?

htatuan avatar Jun 21 '16 09:06 htatuan

I guess that you need to check if is in cache before.

if (razorEngine.IsTemplateCached(TemplateName, typeof(T)))
{
    resultHtml = razorEngine.Run(TemplateName, typeof(T), model);
}
else
{
    resultHtml = razorEngine.RunCompile(BaseTemplateContent, TemplateName, typeof(T), model);
}

traktraktrugui avatar Jun 23 '16 19:06 traktraktrugui

@htatuan A sample application reproducing the problem is needed to fix this (or even better a unit test). Closing until then...

matthid avatar Oct 28 '16 18:10 matthid