Skiasharp: Unable to load DLL in .NET Core: "only valid in the context of an app container"

Created on 13 Mar 2017  路  8Comments  路  Source: mono/SkiaSharp

Hey team,

I'm trying to get SkiaSharp running in a .NET Core web app, but I'm getting an exception:

Unable to load DLL 'libSkiaSharp': This operation is only valid in the context of an app container. (Exception from HRESULT: 0x8007109A)

I've made sure that I have the C++ redistributable installed based on the other DLL loading issue mentioned elsewhere. I've tried this in netcoreapp1.0, netcoreapp1.1 and netcoreapp2.0, as well as with several versions of the SkiaSharp package to no avail. I have posted a simple example that always fails to this repo. Any guidance?

type-bug

Most helpful comment

I investigated this, and I found the cause of the issue. I am building a Universal Windows C++ dll, but this is not really universal. The "universal" actually only applies to UWP apps, not even Windows (Win32) apps. As a result, this issue.

At this time, I am unsure if there is an option to use a universal dll for non-UWP apps. This causes issues because if I build a new dll for win10 .NET Core, I get issue with UWP apps. What is happening right now is that when you install a NuGet that has a win10 native dll into a UWP app, NuGet adds the native dll to the app. Unless the native dll is a universal dll (eg: it may be Win32), it will cause issues at runtime for UWP. If the dll is a universal dll, then it has issues with Win32.

This appears to be a no-win situation, sine both UWP and .NET Core use the same win10 runtime directory, but they each require a different dll.

I will investigate further, and I hope to have a resolution soon.

All 8 comments

@drayfar I worked around this problem by specifying the following in my fsproj file (probably csproj in your case):

<PropertyGroup>
    <TargetFramework>netcoreapp1.0</TargetFramework>    
    <BaseNuGetRuntimeIdentifier>win7-x64</BaseNuGetRuntimeIdentifier>
    <RuntimeIdentifier>win7-x64</RuntimeIdentifier>    
  </PropertyGroup>

As far as I can tell, this error is caused by Win10 native lib sandboxing. Note this probably isn't a sustainable solution

Same issue. The workaround made the project unusable (I'll blame this on VS tooling).

i also have same issue running in vs2015 in windows 10, I tried the workaround but it doesn't work. I tried to run similar code in vs2017 and it's working properly. Visual C++ Redistributable for Visual Studio 2015 is already installed.

I investigated this, and I found the cause of the issue. I am building a Universal Windows C++ dll, but this is not really universal. The "universal" actually only applies to UWP apps, not even Windows (Win32) apps. As a result, this issue.

At this time, I am unsure if there is an option to use a universal dll for non-UWP apps. This causes issues because if I build a new dll for win10 .NET Core, I get issue with UWP apps. What is happening right now is that when you install a NuGet that has a win10 native dll into a UWP app, NuGet adds the native dll to the app. Unless the native dll is a universal dll (eg: it may be Win32), it will cause issues at runtime for UWP. If the dll is a universal dll, then it has issues with Win32.

This appears to be a no-win situation, sine both UWP and .NET Core use the same win10 runtime directory, but they each require a different dll.

I will investigate further, and I hope to have a resolution soon.

I think what's resolved it for me was updating to NetStandard 1.6.1 from i believe 1.6.0 and adding win7-x64 runtime.

After discussing this with the NuGet team, there is a solution for this: https://github.com/NuGet/Home/issues/5042

Hi. I'm still getting the error "Unable to load DLL 'libSkiaSharp': This operation is only valid in the context of an app container." in .net core when trying to use skiasharp in an aws lambda. I've made sure to have the C++ dlls installed and have made sure I'm using the 3.5 nuget as well but still no go. Any ideas?

@cassrauch it is because we haven't released that fix just yet. It is coming soon, but in the mean time is specify the win7 target: https://github.com/mono/SkiaSharp/issues/264#issuecomment-286882054

Was this page helpful?
0 / 5 - 0 ratings