-
Notifications
You must be signed in to change notification settings - Fork 259
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
RazorLight + Azure Functions v3 Working Now #306
Comments
I'm glad to hear you managed to get RazorLight working on Azure, which is, probably, not such a rare use case. But a lack of details of the "fix" makes this issue not as useful as it could be. |
Provided sample works fine, but be careful with updating dependencies - with Microsoft.NET.Sdk.Functions starting with version 3.0.4. RazorLight fail to find dependent assembly (Microsoft.AspNetCore.Razor.Language). |
@sgolomedov As I'm not familiar with Azure Functions at all, would you mind putting together a repro I can run in a sandbox? It would be very helpful towards #299 - I simply don't have the bandwidth to learn how to put together an Azure Functions sample to understand and debug the issues. At minimum, can you provide the stack trace which should include which version of the dependent assembly its trying to find? That would be hepful on top of your clue about v3.0.4. Put another way, are you saying if you fork https://github.com/mrlund/razorlight-azure-functions-v3-test and update ONE dependency (Microsoft.NET.Sdk.Functions) to 3.0.4 it all breaks? |
I'm not the OP but I can confirm this, since I've just been trying this as well. The sample code you mention (by mrlund) works great with the specified package versions. But as soon as you upgrade microsoft.net.sdk.functions to latest stable (3.0.6 in my case) it starts throwing runtime exceptions:
I tried a variety of versions, and sdk versions 3.0.1-3.0.3 work correctly. But sdk packages from 3.0.4 through the latest 3.0.6 cause RazorLight to throw the above error. I'm not seeing an obvious way to get a stack trace, but the last few lines of the log output prior to the error are:
Hope this helps! |
@rzubek Is func.exe something I can run locally? Basically, I don't have time to learn all of Azure Functions but if someone can explain to me step-by-step how to repro the issue on a local machine, I can probably debug this. |
@jzabroski Yes, you can run it locally! Here's a good doc on how to get set up in VS2019: Just the first three sections are enough to test locally. In my testing I created a new Functions project like described in that tutorial, and then replaced the body of the cs file with code from mrlund's project, and added RazorLight from nuget (the latest preview beta version). That's enough to repro. |
@rzubek Thank you very much. Very helpful.
Note to self: Section 1: Prerequisites |
@jzabroski Good news - the problem with azure functions v3 is on their end, and there's a work-around. The newer versions of the functions SDK are cleaning out DLLs too eagerly, and until that's fixed in the SDK, it can be prevented by adding this to .csproj.
Confirmed that this works for RazorLight as well. For future reference, they're tracking it here: Azure/azure-functions-host#5894 |
Awesome, thank you @rzubek for amazing diligence and for sharing your findings. You are a gentleman and a scholar. |
I tried everything, including unofficial beta package, and nothing works. |
@Hogan Have you tried a simple repro in Azure Functions vs your full blown solution? When you say "I tried everything", did you try the solution described by @rzubek above? I can't really help someone who posts a random exception message. There's just zero hope of me figuring out what your problem is. I realize you're probably frustrated, but if you don't document what "trying everything" covers, it doesn't really help - it just adds confusion. |
@jzabroski now I have tried to create new azure function project wih2.0.0-beta7 and example code from readme. I have tried both string rendering, and custom razorlight project.
Conclusion: With freshly created azure function v3, example code and SetOperatingAssembly, it works, even in Azure cloud! :) I am still trying to figure out why it does not work in my full blown solution, but overall I am happy that it works in clean project. The issue with my full blown solution seems to be in my template code. So I consider RazorLight a well working library. Cool :) |
@Hogan Thanks for all that information. Stephen Cleary pointed out to me that much of Azure Functions problems likely come from two areas:
Based on my reading, Microsoft.NET.Sdk.Functions is a bit magical. It does a lot of interesting code generation at compile time, like generating a function.json file for each azure function. |
@Hogan Were you ever able to resolve the error in your existing project? I'm getting the |
@DanielClausen what version of func.exe EDIT: I also see Azure Functions is now on 3.1 |
@jzabroski Function Runtime Version: 3.0.13901.0 |
so func.exe is 3.0.13901.0 but SDK is 3.1? |
Yes, that would be correct, version 3.x is intended with Core 3.1: |
Sorry to be nitpicky, but youre actually using: func.exe version 3.0.13901.0 |
This is incredibly critical to get right to troubleshoot a problem. THe massive tree of dependencies is enormous. Can't search in the wrong haystack for a needle. |
It's fine my apologies for not being clear, I didn't catch on you were asking about the SDK version. In my defense it's past 5 on a Friday and weekend brain is taking over. func.exe version 3.0.13901.0 |
Hey man, It's OK, on Monday, please try 3.0.9. That would probably be the lazy brain way to push past this issue. |
@jzabroski I've got it working! Based on a blog where someone claimed to have RazorLight working with Functions V2 I was using the RazorLight.Unofficial 2.0.0-beta1.3. I switched over to RazorLog 2.0.0-beta9 and now it works. In hindsight I should have tried that sooner. I also tried upgrading to 3.0.9 and that didn't make a difference. Hopefully, this information can help anyone else that might stumble into this issue. The assistance was much appreciated @jzabroski ! |
@DanielClausen I really appreciate that. It's been a long journey herding cats among people who use unofficial RazorLight packages and getting people onto the main line, but it's starting to come back into the fold. |
Can't contribute much additional information to the title, but I've been struggling with rendering razor on azure functions for a while, and suddenly managed to get it working today.
I can't claim credit, but I assume that its a combination of platform and package updates that allows it to work now. Since I've seen many others struggle with this I thought I'd file an issue to let people know that it's possible now.
The catch is that I can't point to why it suddenly started working. I first tried all the tricks in the book, without luck, but suddenly it started working and even a simple repro is working nicely. It's probably just a combination of things wrong in my real project ¯_(ツ)_/¯
Here's the very simple (basically out of the box) version that actually works when deployed to an Azure Function v3:
https://github.com/mrlund/razorlight-azure-functions-v3-test
P.S: In my real world app I have a custom RazorLightProject implementation that loads the templates (and layouts) from blob storage, and that works fine too, so it's not just this simplified version above.
The text was updated successfully, but these errors were encountered: