Skip to content

RazorEngine throw a NotSupportedException when compiling template in Azure Function #526

@csimone86

Description

@csimone86

I must compile a razor view in an azure function to send an email, but something goes wrong. I obtain the a NotSupportedException error: The given path's format is not supported.

Here my code:

private IRazorEngineService _engine;

public MyCtor(bool isTestEnvironment)
{
    TemplateServiceConfiguration configuration = new TemplateServiceConfiguration();
    configuration.Debug = isTestEnvironment;

    this._engine = RazorEngineService.Create(configuration);
}

public string GetHtmlEmailBody(string templateFileName, object emailData, string layoutFileName)
{
    //Get data type of email data
    Type emailDataType = emailData.GetType();

    string layoutFullFileName = Path.Combine(this._layoutPath, layoutFileName);
    string layoutContentString = File.ReadAllText(layoutFullFileName);
    var layout = new LoadedTemplateSource(layoutContentString, layoutFullFileName);

    this._engine.AddTemplate("layoutName", layout);

    string templateFullFileName = Path.Combine(this._templatePath, templateFileName);
    string templateContentString = File.ReadAllText(templateFullFileName);
    var template = new LoadedTemplateSource(templateContentString, templateFullFileName);

    this._engine.AddTemplate("templateName", template);

    this._engine.Compile("templateName"); //<-- Here I get the exception
    string htmlEmailBody = this._engine.Run("templateName", emailDataType, emailData);

    return htmlEmailBody;
}

Paths are similar to D:\\...\\Emails\\Templates.. I am testing locally and it does not work... I have googled and it seems that Azure Functions have some limitations in caching and in file system management, but it is not clear how can I solve the problem. I think I have same problem this person has written here

Any idea how can I solve it? There is something wrong in what I am doing?

I am using RazorEngine 3.10.0

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions