question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Azure Function v2 related issues

See original GitHub issue

Hi,

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:open
  • Created 6 years ago
  • Reactions:1
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
ThatBlokeCalledJaycommented, Mar 8, 2019

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: { …

6reactions
asoetcommented, Jun 20, 2018

This results in a different error: Same as #196

System.NullReferenceException: Object reference not set to an instance of an object.
at RazorLight.Compilation.DefaultMetadataReferenceManager.Resolve(DependencyContext dependencyContext)
at RazorLight.Compilation.RoslynCompilationService.EnsureOptions()
at RazorLight.Compilation.RoslynCompilationService.get_ParseOptions()
at RazorLight.Compilation.RoslynCompilationService.CreateSyntaxTree(SourceText sourceText)
at RazorLight.Compilation.RoslynCompilationService.CreateCompilation(String compilationContent, String assemblyName)
at RazorLight.Compilation.RoslynCompilationService.CompileAndEmit(IGeneratedRazorTemplate razorTemplate)
 at RazorLight.Compilation.RoslynCompilationService.CompileAsync(IGeneratedRazorTemplate razorTemplate)
--- End of stack trace from previous location where exception was thrown ---
   at RazorLight.Compilation.TemplateFactoryProvider.CompileAsync(IGeneratedRazorTemplate razorTemplate)
at RazorLight.Compilation.TemplateFactoryProvider.CreateFactoryAsync(String templateKey)
at RazorLight.RazorLightEngine.CompileTemplateAsync(String key)
at RazorLight.RazorLightEngine.CompileRenderAsync(String key, Object model, Type modelType, ExpandoObject viewBag)
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found