RazorEngineCore
RazorEngineCore copied to clipboard
UnauthorizedAccessException when running on Azure Web App service
My implementation of RazorEngineCore works fine in my local Windows development environment, but throws UnauthorizedAccessException when deployed as part of an Azure Web App (on a Windows instance).
As the following exception message indicates, the issue arises during template compile:
System.UnauthorizedAccessException: Access is denied. (0x80070005 (E_ACCESSDENIED))
at System.Runtime.Loader.AssemblyLoadContext.LoadFromStream(IntPtr ptrNativeAssemblyBinder, IntPtr ptrAssemblyArray, Int32 iAssemblyArrayLen, IntPtr ptrSymbols, Int32 iSymbolArrayLen, ObjectHandleOnStack retAssembly)
at System.Runtime.Loader.AssemblyLoadContext.InternalLoad(ReadOnlySpan`1 arrAssembly, ReadOnlySpan`1 arrSymbols)
at System.Reflection.Assembly.Load(Byte[] rawAssembly, Byte[] rawSymbolStore)
at RazorEngineCore.RazorEngineCompiledTemplate`1..ctor(RazorEngineCompiledTemplateMeta meta)
Strangely, some templates work perfectly, while others throw the above exception, with seemingly no significant difference between their template structure or content.
I've tried multiple different ways of supplying the templates to RazorEngineCore, including embedded resource files and hard-coded strings, but all approaches suffer the same exceptions.
Interestingly, the problem only occurs when the RazorEngineCore implementation and the templates are defined in a class library. If I move these elements into the root ASP.NET Core Web API project, RazorEngineCore renders reliably.
If you have any suggestions, I would appreciate them. Many thanks.