Description
I have an AzureFunctions application that is using .netcoreapp3.0 and the v3-preview. It runs perfectly fine locally but when I deploy it to Azure I get the following error as soon as I use Skia:
Exception while executing function: <--- The type initializer for 'SkiaSharp.SKAbstractManagedStream' threw an exception. <--- Unable to load DLL 'libSkiaSharp' or one of its dependencies: The specified module could not be found. (0x8007007E)
The only difference I've noticed from locally and deployed is locally the runtimes folder which contains libSkiaSharp.dll is within the bin and deployed on Azure it's on the same file level as bin.
The files/folders on the functions app are restricted access so I can't manually upload the runtimes folder into the bin to see if that helps.
Thoughts?
Code
Expected Behavior
Actual Behavior
Basic Information
Screenshots
Reproduction Link
I have same issue in .netcoreapp3.0 service on docker
I had a look at this and it is a tad annoying, but it appears that Azure Functions are not quite perfect in the way things work. Looks like the runtime does not load the native files like other .net core apps and websites.
But, this is not to say that we can't do anything about it. As part of the publish step, we can hook in there and manually copy the files we know we will need. For example, we know we are going to need the native libSkiaSharp.dll, so we can copy it in a custom target in the .csproj.
<Target Name="CopyRequiredNativeAssets" AfterTargets="_FunctionsPostPublish">
<ItemGroup>
<NativeAssetToCopy Include="$(PublishDir)runtimes\win-x86\native\libSkiaSharp.dll" />
</ItemGroup>
<Copy SourceFiles="@(NativeAssetToCopy)" DestinationFolder="$(PublishDir)bin" />
</Target>
I think this is a missing feature on the functions side, so I added a comment on an open issue there. Not sure what will happen, but we can try: https://github.com/Azure/Azure-Functions/issues/622#issuecomment-555850877 Maybe drop a vote?
I did notice that the runtime seems to be 32-bit on the cloud, we we have to use that one there.
I have created a test repo (https://github.com/mattleibow/SkiaSharpFunctions) and have something hosted for your viewing pleasure (https://skiasharpfunctions.azurewebsites.net/api/images)
Most helpful comment
I had a look at this and it is a tad annoying, but it appears that Azure Functions are not quite perfect in the way things work. Looks like the runtime does not load the native files like other .net core apps and websites.
But, this is not to say that we can't do anything about it. As part of the publish step, we can hook in there and manually copy the files we know we will need. For example, we know we are going to need the native
libSkiaSharp.dll, so we can copy it in a custom target in the .csproj.I think this is a missing feature on the functions side, so I added a comment on an open issue there. Not sure what will happen, but we can try: https://github.com/Azure/Azure-Functions/issues/622#issuecomment-555850877 Maybe drop a vote?
I did notice that the runtime seems to be 32-bit on the cloud, we we have to use that one there.
I have created a test repo (https://github.com/mattleibow/SkiaSharpFunctions) and have something hosted for your viewing pleasure (https://skiasharpfunctions.azurewebsites.net/api/images)