oxyplot / oxyplot

A cross-platform plotting library for .NET
https://oxyplot.github.io/
MIT License
3.3k stars 963 forks source link

SkiaSharp.Wpf Visual Studio XAML designer crash #2075

Open Enduteri opened 7 months ago

Enduteri commented 7 months ago

Steps to reproduce

  1. Install nuget package OxyPlot.SkiaSharp.Wpf into any WPF project
  2. Add PlotView to MainWindow.xaml or any window
  3. Build project

Platform: WPF .NET version: netf472 Oxyplot SkiaSharp Wpf version: 2.1.2 Visual Studio Community 2022 x64 17.9.6

Actual behaviour

Visual Studio designer crashes trying to load xaml file containing skia:plotview objects. It's purely a designer problem, program can compile and run OK without designer I've also tried this with x86 project build and AnyCPU, same issue XAML designer crashes trying to create RenderContext, fails on libSkiaSharp.dll, file is present in the bin catalog This crashes designer for the entire project, no way around it, won't be able to use it.

Workaround

Create PlotView in Control code and add to View when loaded

Error Details:

`System.DllNotFoundException Dll was not found.

System.AggregateException System.DllNotFoundException: Unable to load DLL 'libSkiaSharp': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at SkiaSharp.SkiaApi.sk_paint_new() at SkiaSharp.SKPaint..ctor() at OxyPlot.SkiaSharp.SkiaRenderContext..ctor() in C:\Users\Murdo\source\repos\oxyplot\Source\OxyPlot.SkiaSharp\SkiaRenderContext.cs:line 24 at OxyPlot.SkiaSharp.Wpf.PlotView.CreateRenderContext() in C:\Users\Murdo\source\repos\oxyplot\Source\OxyPlot.SkiaSharp.Wpf\PlotView.cs:line 52 at OxyPlot.Wpf.PlotViewBase.OnApplyTemplate() in C:\Users\Murdo\source\repos\oxyplot\Source\OxyPlot.Wpf.Shared\PlotViewBase.cs:line 190 at System.Windows.FrameworkElement.ApplyTemplate() at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.Grid.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.Border.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.Control.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.Grid.MeasureOverride(Size constraint) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.ContextLayoutManager.UpdateLayout() at Microsoft.VisualStudio.DesignTools.WpfTap.WpfVisualTreeService.LiveMarkup.TapInstanceManager.GetFrameworkElementNameScope(DependencyObject ancestor) at Microsoft.VisualStudio.DesignTools.WpfTap.WpfVisualTreeService.LiveMarkup.TapInstanceManager.UpdateNameRegistration(TapInstanceBuilderContext context, XamlAction xamlAction) at Microsoft.VisualStudio.DesignTools.WpfTap.WpfVisualTreeService.LiveMarkup.TapInstanceManager.ProcessCurrentThreadActions(TapInstanceBuilderContext context) at Microsoft.VisualStudio.DesignTools.WpfTap.WpfVisualTreeService.LiveMarkup.TapInstanceManager.UpdateInstances(TapInstanceBuilderContext context) at Microsoft.VisualStudio.XSurface.Wpf.DesignerTapInstanceManager.UpdateInstances(TapInstanceBuilderContext context) at Microsoft.VisualStudio.XSurface.Wpf.Tap.SurfaceService.InstanceBuildDocumentInternal(Int32 documentId, Object rootObject) at Microsoft.VisualStudio.XSurface.Wpf.Tap.SurfaceService.HandleCreateSurfaceInternal(CreateSurfaceRequestInfo requestInfo) at Microsoft.VisualStudio.DesignTools.RuntimeHost.TapOM.ResponseWithError.ThrowIfFailed() at Microsoft.VisualStudio.DesignTools.SurfaceDesigner.Documents.SurfaceIsolation.DesignerInstanceManager.d57.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.VisualStudio.DesignTools.XamlSurfaceDesigner.Views.IsolatedSurfaceImageHost.d67.MoveNext()

System.AggregateException One or more errors occurred.`

mikezw commented 6 months ago

Hi, you can take a look of #1781 . Try copy "libSkiaSharp" dlls to system folder.