toddams / RazorLight

Template engine based on Microsoft's Razor parsing engine for .NET Core
Apache License 2.0
1.5k stars 259 forks source link

Azure functions V4 issue #540

Closed w1ckedmellow closed 5 months ago

w1ckedmellow commented 7 months ago

While I was migrating to Azure Functions V4 I stambled upon an issue with a dependency. I cannot find a way to solve this, and I'm reaching out for help.

image

To Reproduce I prepared a simple repo that recreates the issue, by running RenderRazorLight function. https://github.com/w1ckedmellow/Azure-functions-v4-razor-light-issues.git

Expected behavior Compilation a template from a path or Assembly embeded resource razorLightEngine.CompileRenderAsync( templatePath, templateModel )

Additional context Error System. Private. CoreLib: Exception while executing function. RazorLight: Could not load file or assembly 'Microsoft. Extensions. DependencyModelJ Version=6.O.O.O

jzabroski commented 6 months ago

Thanks, the repro is helpful. I may take a look this weekend.

rn1d commented 6 months ago

I was having the same issue. I was updating my Azure Functions app from v3 runtime to v4 runtime running .NET 6.0 in-process model. While the app compiled and ran fine, I got the same exception when calling razorLightEngine.CompileRenderAsync(templatePath, model).

I was able to work around it by migrating my app to the isolated worker process model running .NET 8.0. This approach might make more sense for some people, given the isolated worker model is the recommended approach going forward.

I suspect RazorLight might also work in isolated mode with .NET 6.0, but in my case, going with .NET 8.0 was preferrable.

Hope that helps!

jzabroski commented 6 months ago

I've been telling people to use isolated worker mode forever.

The default Azure Functions stuff is terrible.

w1ckedmellow commented 5 months ago

Thank you @rn1d for the tip and helpful links! :) I migrated one of my functions to 'dotnet-isolated' and it worked smoothly. Soon I will add a working branch of my test above. Hiope it will help otehrs.

@jzabroski maybe it would be beneficial to add some info about this Azure functions limitations on the project readme.

jzabroski commented 5 months ago

Respectfully, did you read the part of the Readme where this exact topic is covered?

If you don't think it's clear enough, go submit a PR. - Don't message people saying something that's documented, isn't documented.

Screenshot_20240121_135725_GitHub.jpg