Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I'm getting intermittent "No template exists with name" errors #48

Closed
Madd0g opened this issue May 1, 2012 · 4 comments
Closed

I'm getting intermittent "No template exists with name" errors #48

Madd0g opened this issue May 1, 2012 · 4 comments

Comments

@Madd0g
Copy link

Madd0g commented May 1, 2012

It's very weird, normally everything works, every now and again, I get this error on several templates. I restart the ASP.Net dev server and it goes away, then after some code rebuilds it comes back. No errors are thrown while calling Service.Compile, but when I call Service.Run it comes back with the "no template exists" error.

I fetch and compile templates on application start, it takes about 10 seconds in a newly spun thread with parallel foreach - if the template is accessed while it's compiling - can that cause this issue?

Are the compiled templates saved to disk as files? Could there be name collisions? What could cause a template to compile but not run afterwards?

Without parallelization it takes 30+ seconds, would be cool if there was a way to avoid recompiling them on every server restart.

Stack Trace :   at RazorEngine.Templating.TemplateService.Run[T](String name, T model)
in c:\*path*\RazorEngine3\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 990

Thanks

@Antaris
Copy link
Owner

Antaris commented May 21, 2012

Are you running the templates while trying to compile them in parallel?

@Madd0g
Copy link
Author

Madd0g commented Jun 16, 2012

Woops, didn't see your response there :(

It is possible that sometimes the code reaches the call to the template before the loading-code finished running (the loading is an async process because it takes more than 20 seconds, I have a lot of templates), what I know is - the problem doesn't go away with time.

However, it's highly intermittent and I couldn't find a solid cause for this. I've added all kinds of logging messages all around the template loading code and it seems like all templates are loaded correctly (like I said in the OP - I get no errors at all while loading, ever), but the "template doesn't exists" errors don't go away, I have to restart the server to get them to work.

I have the template-loading code in the Application_Start event, maybe because the dev-server keeps recreating them it creates an I/O problem? I really don't know but it happens often enough to make me worried of what will happen in production (not there yet)

I'm on a slightly outdated version, haven't updated in months, if that matters

Thanks

@Madd0g
Copy link
Author

Madd0g commented Jul 16, 2012

I'm getting these errors under IIS as well :(
Is there anything I can check or do?
I get the error even if I do the compiling in the main thread (no accesses to the template before the compile)

this is how I compile the templates:

Parallel.ForEach(templates, new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount },
        (templateObj, state) =>
            {
                try
                {
                    Service.Compile<ILoveObject>(templateObj.templateText, templateObj.Id.ToString());

                    compiledTemplates.Add(templateObj); //for access via 'Id'

                }
                catch (Exception e)
                {
                    log.Error(String.Format("Error compiling template {0}", templateObj.Name));
                    log.Error(e);
                }
            }
        );

Then I find the correct template in the compiledTemplates list and Run var result = Service.Run(templateId, loveObject); and get the "No template exists with name" exception.

Thanks.

@Madd0g
Copy link
Author

Madd0g commented Jul 16, 2012

I tried to remove the parallel thing, but it was to slow, so I just adjusted to compile on demand, hope it was because of the parallelization and this solves the problem.

@Antaris Antaris closed this as completed Jan 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants