mono / SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
MIT License
4.24k stars 526 forks source link

[BUG] Visual Studio is unable to load 32-bit assembly 'SkiaSharp.dll'. Do you want to use the Windows Forms out-of-process designer ... #2914

Open Costigan opened 4 days ago

Costigan commented 4 days ago

Description

I have a desktop winforms application that has been using SkiaSharp 2.88.8. After updating to 3.0.0-preview.3.1 (and updating several api calls), I now cannot use the normal windows forms designer, and the out-of-process designer doesn't work in this case, only partially displaying the form.

image

Using Microsoft Visual Studio Community 2022 (64-bit) - Preview, Version 17.11.0 Preview 2.1 Microsoft .NET Framework Version 4.8.09037

I've confirmed that SkiaSharp.NativeAssets.Win32.3.0.0-preview.3.1 is in my packages/ directory. Under SkiaSharp.NativeAssets.Win32.3.0.0-preview.3.1/runtimes, I see win-x64/native/ and win-x86/native/, and the copies of libSkiaSharp.dll in those directories look like they are compiled for the right architectures. Using file, I see PE32+ under win-x64 and PE32 under win-x86.

I've reverted back to version 2.88.8, and the windows forms designer works again. I'm stumped as to why SkiaSharp.dll isn't loading.

Note that the SkiaSharp version pulldown below doesn't include 3.0.0-preview.3.1

I normally build the app for the x64 platform. I've also built it for the Any CPU platform, because I have some unrelated controls that need to be built that way to load into the designer.

Code

n/a

Expected Behavior

I expected the windows forms designer to open showing me my form as usual.

Actual Behavior

I got the error message shown. The out-of-process designer does open, but it's not fully usable yet.

Version of SkiaSharp

3.x (Alpha)

Last Known Good Version of SkiaSharp

2.88.2 (Previous)

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Windows

Platform / Operating System Version

Windows 10 Enterprise 10.0.19045 build 19045 .NET Framework 4.8.09037

Devices

Dell Windows laptop

Relevant Screenshots

image

Relevant Log Output

I haven't been able to generate a log of dll load attempts and failures.

Code of Conduct

mattleibow commented 3 days ago

Are you able to attach a sample project? I want to see if there is some random project setting or something.

Costigan commented 3 days ago

Bug1.zip

This sample project shows an error, although the symptoms are different from my bug report, because, here, I'm starting a fresh project and trying to create a new form and then adding an SKGLControl to it. In my bug report, I have several existing forms that have controls subclassed from SKGLControl that now won't load into the designer (and which worked in v2.88.8). I believe the underlying cause is the same, but as I don't understand it, I don't really know.

Using Visual Studio Community 2022 (64-bit) Version 17.9.6 and Microsoft .NET Framework Version 4.8.09037

  1. Create a new Windows Forms App (.NET Framework)

  2. Using the Manage NuGET Packages for Solution windows in visual studio a. Installed SkiaSharp by Microsoft (the one with 98.1M downloads), version 3.0.0-preview.3.1

    See Capture1.PNG in the project. This dialog warned me about PackageReference. In this case, I selected that option rather than Packages.config, and it installed SkiaSharp and the native assets.

    b. Installed SkiaSharp.Views.WindowsForms by Microsoft, 528K downloads. (Should I use SkiaSharp.Views.Desktop.Common? What's the difference?)

  3. Tried to drag SKGLControl out from the toolbox. This failed, generating the dialog in Capture2.PNG.

  4. Tried to drag out SKControl from the toolbox. This failed, generating Capture3.PNG

  5. Added an SKGLControl in the main form's constructor with a PaintSurface event handler and ran th eprogram using the Any CPU platform. This worked, generating Capture4.PNG.

  6. I added an x64 platform, compiled again and ran it. This worked too, generating the same output.


In a second attempt (I haven't zipped this project), I selected Packages.config for the package manager format. In this case, dragging an SKGLControl from the toolbox to the main form succeeded, but the app failed at runtime. See Capture5.PNG.


In a third attempt (I haven't zipped this project), I used SkiaSharp v2.88.8 and Packages.config for the package manager format. In this case, everything worked as expected. Selecting PackageReference also worked.

Costigan commented 3 days ago

I should have explicitly said that I deleted the obj and bin directories from the solution to get it under the upload file size limit and that dotnet restore restores the packages. After doing that, this project works, but dragging SKGLControl from the toolbox still doesn't work, that is, the symptom is the same.