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

Could not load file or assembly 'Microsoft.CodeAnalysis #23

Closed
Nilotaviano opened this issue Jul 9, 2020 · 5 comments
Closed

Could not load file or assembly 'Microsoft.CodeAnalysis #23

Nilotaviano opened this issue Jul 9, 2020 · 5 comments

Comments

@Nilotaviano
Copy link

Nilotaviano commented Jul 9, 2020

I'm trying to use this lib to generate HTML on an Azure Function, not sure what could be going wrong here.

public static string RenderViewToString(RedactedViewModel model)
{
    const string templateName = "redacted";
    string viewPath = Path.Combine(Constants.VIEW_FOLDER_PATH, templateName + ".cshtml");

    return new RazorEngine()
        .Compile(File.ReadAllText(viewPath))
        .Run(model);
}

System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
Source=RazorEngineCore
StackTrace:
at RazorEngineCore.RazorEngineCompilationOptions..ctor()
at RazorEngineCore.RazorEngineCompilationOptionsBuilder..ctor(RazorEngineCompilationOptions options)

@Nilotaviano
Copy link
Author

Even running your Basic Usage example gives the same error

public static string RenderViewToString(DailyTicketReportViewModel model)
{
    IRazorEngine razorEngine = new RazorEngine();
    IRazorEngineCompiledTemplate template = razorEngine.Compile("Hello @Model.Name");

    string result = template.Run(new
    {
        Name = "Alexander"
    });

    return result;
}

@adoconnection
Copy link
Owner

It is something to do with framework version, are you running function against net core 3?
@AndyMDoyle may bring some light.

@AndyMDoyle
Copy link

@Nilotaviano, I ran in to the same issue a few weeks ago and it drove me crazy trying to find the problem.

It turns out there's a known issue with Azure Functions where assemblies are cleaned up during build and this currently results in some assemblies being removed by mistake if you have installed a newer version of an assembly than expected.

To work around the issue, add the following to your csproj file to prevent the cleanup:

  <PropertyGroup>
    <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
  </PropertyGroup>

The Azure Functions team are aware of this and are working on fixing it. You can follow along on the issue at Azure/azure-functions-host#5894

@Nilotaviano
Copy link
Author

Thanks @AndyMDoyle, that works.

@rochapablo
Copy link

@AndyMDoyle thank you so much! You just save the day.

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

4 participants