Skip to content
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

[BUG] libSkiaSharp.dll in x64 and x86 folder not been used #1311

Closed
JackLi-tg opened this issue May 27, 2020 · 6 comments
Closed

[BUG] libSkiaSharp.dll in x64 and x86 folder not been used #1311

JackLi-tg opened this issue May 27, 2020 · 6 comments
Milestone

Comments

@JackLi-tg
Copy link

Description

SkaiShapr version:1.68.3
Environment: Visual Stdio 2019
Project: .NetFramework project (Please note the issue not happening in .NetCore Project)
Compile platform: Any CPU

Issue:
When compile the project, libSkiaSharp.dll been copied to
Bin\Debug\x64\libSkiaSharp.dll
Bin\Debug\x86\libSkiaSharp.dll
Bin\Debug\libSkiaSharp.dll
but it seems like application not using any of those Dlls in x64 nor x86. Instead application always using the one the Debug folder.

My understanding is that the Bin\Debug\libSkiaSharp.dll shouldn't be there at all, app should use the ones in x64/x86 folder depending on current application platform (any cpu/x86/x64).

Code

No code needed, just reference the nugetpackage, and compile.

Expected Behavior

Application should use Bin\Debug\x86(x64)libSkiaSharp.dll depending on current application platform (any cpu/x86/x64) automatically

Actual Behavior

Application always using the one in Bin\Debug\libSkiaSharp.dll.

Basic Information

  • Version with issue: 1.68.3
  • Last known good version: Unknown
  • IDE: Visual Studio 2019 - Windows 10
  • Platform Target Frameworks: Any CPU
    • Windows Classic: Windows 10
  • Target Devices: Windows application

Screenshots

none

Reproduction Link

@ziriax
Copy link
Contributor

ziriax commented Jun 3, 2020

I'm facing the same issue. I made a unit test project (.NET 4.8, Any CPU) that references a .NET Standard 2.0 library (Any CPU), and the latter references SkiaSharp 1.68.3.

I got the following exception:

Test method SkiaUnitTests.SkRenderTargetTests.New_RenderTarget_IsTransparent threw exception: 
System.TypeInitializationException: The type initializer for 'SkiaSharp.SKImageInfo' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'libSkiaSharp': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
    at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()
   at SkiaSharp.SKImageInfo..cctor()

When using ProcMon, it seems the x86 and x64 directories where the libSkiaSharp.dll is located are ignored:

C:\dev\express\Source\Framework\Solutions\SkiaUnitTests\SkiaUnitTests\bin\Debug\libSkiaSharp.DLL => not found

Manually copying the x86\libSkiaSharp.dll to the Debug folder works, but I would like to avoid
this.

Any tips?

@ziriax
Copy link
Contributor

ziriax commented Jun 3, 2020

As a temporary workaround, I added the following in a static constructor in my .NET Standard 2.0 project that references SkiaSharp, but this is not a good nor secure solution:

		[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		static extern bool SetDllDirectory(string lpPathName);

		static SkGraphicsFactory()
		{
			if (Environment.OSVersion.Platform == PlatformID.Win32NT)
			{
				// HACK: Workaround https://github.com/mono/SkiaSharp/issues/1311
				SetDllDirectory(Environment.Is64BitProcess ? "x64" : "x86");
			}
		}

@chrisfoulds
Copy link

Exact same issue as mine, but mine is on iOS.
How would I do a similar hack for iOS?
#1304

@mattleibow
Copy link
Contributor

This is slightly different as iOS is supposed to get it right. This issue is really just for the old Full Framework on Windows. The new .NET Core system does not need this. As much as I like Full Framework, it probably will not get fixed any time soon - especially since all the new platforms work.

Not that this is unimportant, but we are focusing on making .NET Core work best. And, this issue has a decent workaround for now.

@chrisfoulds I replied to that issue.

@mattleibow
Copy link
Contributor

Fixing this in #1342

@mattleibow
Copy link
Contributor

Fixed in #1342 and will be in the next version.

No longer is libSkiaSharp.dll copied to the root directory as there is no way to know which one is meant to be used. Instead, they are copied into the x86 and x64 sub directories and the library will load the correct one.

@mattleibow mattleibow added this to the v2.80.0 milestone Jul 9, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Aug 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants