Azure Function v2 related issues
See original GitHub issueHi,
I’m trying to use RazorLight in an Azure Function v2, but I get a “Could not find or load a specific file” when it tries to compile the view.
I can’t work out where this issue lies and wondered if it had anything to do with this:
When RazorLight compiles your template - it loads all the assemblies from your entry assembly and creates MetadataReference from it. This is a default strategy and it works in 99% of the time. But sometimes compilation crashes with an exception message like “Can not find assembly My.Super.Assembly2000”. In order to solve this problem you can pass additional metadata references to RazorLight.
Any help would be appreciated 😃
Thanks
Error
[19/03/2018 1:51:18 AM] A ScriptHost error has occurred
[19/03/2018 1:51:18 AM] Exception while executing function: Maintenance. RazorLight: Could not load file or assembly 'Microsoft.Extensions.DependencyModel, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'Microsoft.Extensions.DependencyModel, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
[19/03/2018 1:51:18 AM] Exception while executing function: Maintenance
[19/03/2018 1:51:18 AM] Exception while executing function: Maintenance. RazorLight: Could not load file or assembly 'Microsoft.Extensions.DependencyModel, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'Microsoft.Extensions.DependencyModel, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
[19/03/2018 1:51:18 AM] Function completed (Failure, Id=eafaae85-9698-4b0f-ada8-13061e0837f7, Duration=2409ms)
[19/03/2018 1:51:18 AM]
[19/03/2018 1:51:18 AM] Executed 'Maintenance' (Failed, Id=eafaae85-9698-4b0f-ada8-13061e0837f7)
[19/03/2018 1:51:18 AM] System.Private.CoreLib: Exception while executing function: Maintenance. RazorLight: Could not load file or assembly 'Microsoft.Extensions.DependencyModel, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'Microsoft.Extensions.DependencyModel, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
[19/03/2018 1:51:18 AM] Function had errors. See Azure WebJobs SDK dashboard for details. Instance ID is 'eafaae85-9698-4b0f-ada8-13061e0837f7'
[19/03/2018 1:51:18 AM] System.Private.CoreLib: Exception while executing function: Maintenance. RazorLight: Could not load file or assembly 'Microsoft.Extensions.DependencyModel, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'Microsoft.Extensions.DependencyModel, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
Code
var path = $"{ context.FunctionAppDirectory }/Templates";
var engine = new RazorLightEngineBuilder()
.UseFilesystemProject(path)
.UseMemoryCachingProvider()
.Build();
string result = await engine.CompileRenderAsync("MonthlyReport.cshtml", new MonthlyReport { DateRun = DateTime.Now });
View
@using` RazorLight
@using Models
@inherits TemplatePage<MonthlyReport>
<html>
Date run: @Model.DateRun
</html>
Model
using System;
using System.Collections.Generic;
using System.Text;
namespace Models
{
public class MonthlyReport
{
public DateTime DateRun { get; set; }
}
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Issues · Azure/Azure-Functions
Azure.WebJobs.Extensions.Storage version 5.1.2 and Azure Functions v. 4.2.0, error: "The specified container already exists", status 409 Needs: Triage ...
Read more >Troubleshoot Python errors in Azure Functions
This article provides information to help you troubleshoot errors with your Python functions in Azure Functions. This article supports both ...
Read more >Azure Functions runtime versions overview
Azure Functions supports multiple versions of the runtime. ... To resolve issues your function app may have when running on the latest major ......
Read more >Azure function app upgrade, function V4 ...
This blog will talk about some common issues you may meet when you try to upgrade your Azure function from older runtime version...
Read more >Azure Functions diagnostics Overview
Learn how you can troubleshoot issues with your function app with Azure Functions diagnostics.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Same issue here. Sad times. Are there any updates to this?
… [08/03/2019 22:49:47] Executed ‘Render’ (Failed, Id=cbf33eb5-bef7-4d1e-8133-b4a1504b55a5) [08/03/2019 22:49:47] System.Private.CoreLib: Exception while executing function: Render. RazorLight: Can’t load metadata reference from the entry assembly. Make sure PreserveCompilationContext is set to true in *.csproj file. [08/03/2019 22:49:47] Executed HTTP request: { …
This results in a different error: Same as #196