SkiaSharp icon indicating copy to clipboard operation
SkiaSharp copied to clipboard

[BUG] Unable to load library 'libSkiaSharp' in Visual Studio Design Mode

Open jonchardy opened this issue 3 years ago • 1 comments

Description When using SkiaSharp.Views.WindowsForms, one cannot create SkiaSharp classes (in this case, SKFont) within a custom control's constructor without breaking Visual Studio's design mode. This only seems to apply to .NET Framework projects. This is a problem for library authors looking to create controls using SkiaSharp rendering.

Code

    [ToolboxItem(true)]
    public partial class MyCustomControl : SKControl
    {
        private SKFont myFont;

        public MyCustomControl()
        {
            InitializeComponent();

            myFont = new SKFont
            {
                Typeface = SKTypeface.FromFamilyName("Segoe UI"),
                Subpixel = true
            };
        }

        protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
        {
            base.OnPaintSurface(e);
            var c = e.Surface.Canvas;
            c.Clear();
            c.DrawText("Test", new SKPoint(20, 20), new SKPaint());
        }
    }

Expected Behavior One should be able to add a control that inherits from SKControl during design mode, even if it constructs SkiaSharp classes in its constructor.

Actual Behavior An exception is thrown when dropping the custom control onto a form in .NET Framework.

Basic Information

  • Version with issue: 2.80.3
  • Last known good version: unknown
  • IDE: Visual Studio 2022
  • Platform Target Frameworks: WindowsForms on .NET Framework
  • Target Devices: Windows 10
Detailed IDE/OS information (click to expand)

Microsoft Visual Studio Community 2022 (64-bit) - Preview
Version 17.2.0 Preview 2.1

Reproduction Link

https://github.com/jonchardy/SkiaSharpDesignModeRepro

jonchardy avatar Apr 15 '22 14:04 jonchardy

请问得到解决了吗

7emotions avatar Aug 10 '24 01:08 7emotions