Skip to content

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

Closed

Description

@Nilotaviano

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)

Activity

  1. Nilotaviano commented on Jul 9, 2020

    @Nilotaviano
    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;
    }
    
  2. adoconnection commented on Jul 9, 2020

    @adoconnection
    Owner

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

  3. AndyMDoyle commented on Jul 9, 2020

    @AndyMDoyle

    @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

  4. Nilotaviano commented on Jul 14, 2020

    @Nilotaviano
    Author

    Thanks @AndyMDoyle, that works.

  5. rochapablo commented on Aug 12, 2020

    @rochapablo

    @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

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