-
Notifications
You must be signed in to change notification settings - Fork 263
Description
Introduction
There are several NuGet packages that ship with a managed assembly and also with additional native binaries that are copied to the "runtimes" folder below the binaries.
SkiaSharp is an example of such a library:
C:\P\MYPROJECT\SOURCE\WEBAPP\BIN\RELEASE\NET8.0\RUNTIMES
├───osx
│ └───native
│ libSkiaSharp.dylib
│
├───win-arm64
│ └───native
│ libSkiaSharp.dll
│
├───win-x64
│ └───native
│ libSkiaSharp.dll
│
└───win-x86
└───native
libSkiaSharp.dll
There is a "SkiaSharp.dll" (managed) directly in "C:\P\MYPROJECT\SOURCE\WEBAPP\BIN\RELEASE\NET8.0" and the above folder structure.
In a C# application (e.g. ASP.NET Core MVC, Console or Windows Forms) the build system somehow ensures that the native binaries are copied to the output folder.
In CS-Script this is not the case. Resulting in runtime errors.
Example
As an example, consider the following minimal CS-Script file "skipasharp-test.cs"::
//css_nuget SkiaSharp
//css_nuget SkiaSharp.NativeAssets.Win32
using SkiaSharp;
class Program
{
static void Main()
{
try
{
int width = 800;
int height = 600;
using var bitmap = new SKBitmap(width, height);
}
catch (Exception x)
{
Console.WriteLine(x.ToString());
while(x.InnerException!=null)
{
x = x.InnerException;
Console.WriteLine();
Console.WriteLine(x.ToString());
}
}
}
}Running it from my Windows 11 command line with this:
css /dbg "skiasharp-test.cs"This results in the following:
System.TypeInitializationException: The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.
---> System.DllNotFoundException: Unable to load DLL 'libSkiaSharp' or one of its dependencies: Das angegebene Modul wurde nicht gefunden. (0x8007007E)
at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()
at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()
at SkiaSharp.SKImageInfo..cctor() in /_/binding/SkiaSharp/SKImageInfo.cs:line 48
--- End of inner exception stack trace ---
at SkiaSharp.SKBitmap..ctor(Int32 width, Int32 height, Boolean isOpaque) in /_/binding/SkiaSharp/SKBitmap.cs:line 33
at Program.Main() in C:\Ablage\skiasharp-test.cs:line 15
System.DllNotFoundException: Unable to load DLL 'libSkiaSharp' or one of its dependencies: Das angegebene Modul wurde nicht gefunden. (0x8007007E)
at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()
at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()
at SkiaSharp.SKImageInfo..cctor() in /_/binding/SkiaSharp/SKImageInfo.cs:line 48The exception reads (in German):
System.DllNotFoundException: Unable to load DLL 'libSkiaSharp' or one of its dependencies: Das angegebene Modul wurde nicht gefunden. (0x8007007E)
And in English:
System.DllNotFoundException: Unable to load DLL 'libSkiaSharp' or one of its dependencies: The specified module could not be found. (0x8007007E)
I honestly do think that you thought about such cases and have a solution; I simply cannot figure it out for now.
My question
Is it possible that CS-Script supports NuGet packages both with managed and native binaries as e.g. with SkiaSharp?
More information
-
In case it helps, here is the SkiaSharp LibraryLoader.cs
-
I do think that this file is the reason why the binaries are automatically copied to the output folder. (See also the NuGet package "SkiaSharp.NativeAssets.Win32" in the "buildTransitive" folder).