Open tbconrad opened 6 years ago
Perhaps the scheduled task has no sufficient permission to read from folder where template is?
@csimone86 I thought that too but the account is a local administrator on the server and the templates are in the application folder.
So I was able to reproduce this. I created a sample console app and put it up on GitHub as RazorEngine_Test. Compile and run the project and it will run successfully from the debug or release folder. Copy all the files from the folder you ran it from and paste them into a new folder then run it again.
2018-07-26 12:57:22,991 INFO RazorEngine_Test.Logger Error Details: Could not resolve template ExceptionEmail.cshtml
Stack: at RazorEngine.Templating.ResolvePathTemplateManager.ResolveFilePath(String name)
at RazorEngine.Templating.ResolvePathTemplateManager.GetKey(String name, ResolveType resolveType, ITemplateKey context)
at RazorEngine.Templating.RazorEngineService.GetKey(String cacheName, ResolveType resolveType, ITemplateKey context)
at RazorEngine.Templating.DynamicWrapperService.GetKey(String name, ResolveType resolveType, ITemplateKey context)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.
UPDATE 3: It seems that the TemplateServiceConfiguration is not working as designed or the examples I worked off of are incorrect. I updated the test project with the 2 lines below and that solved my issue. I don't think this was the intended implementation method but it works. Posting because I know someone will run into the same issue.
var config = new TemplateServiceConfiguration
{
TemplateManager = new ResolvePathTemplateManager(new[] {"EmailTemplates"}),
DisableTempFileLocking = true
};
Engine.Razor = RazorEngineService.Create(config);
//new
string path = AppDomain.CurrentDomain.BaseDirectory;
string filePath = $"{path}EmailTemplates\\ExceptionEmail.cshtml";
//
var emailHtmlBody = Engine.Razor.RunCompile(filePath, null, model);
Perhaps are you in an Isolated (hosted) environment? I do not know exactly what I mean... I mean, is there a process that run you code?
Perhaps the base directory you see is the directory where the exe of the process that run your code reside... so you need to force it
@csimone86 No isolated or hosted environment, just an on-prem server trying to run a console application from a local administrator account
I have a console application that uses RazorEngine to send email based on the run of the application. I am successfully able to send emails both in the development IDE and from running the console application via the executable. However, when I run the console application from a scheduled task I receive an error "Could not resolve template" on line,
var emailHtmlBody = Engine.Razor.RunCompile("ResponseErrors.cshtml", null, model);
has anyone run into this?
UPDATE 1:
UPDATE 2: There is no RazorEngine... folder that was created in the user's temp folder.