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

use OxyPlot.SkiaSharp.Wpf , version: 2.1.0-Preview1, .net framework 4.5 or 4.8 #1760

Closed
mzy666888 opened this issue Apr 27, 2021 · 2 comments

Comments

@mzy666888
Copy link

Steps to reproduce

  1. On MainWindow.xmal add code:
 <oxyplot:PlotView x:Name="MyOxyPlotView">
        </oxyplot:PlotView>
  1. On MainWindow.xmal.cs add code:
            var model = new OxyPlot.PlotModel();
            model.Axes.Add(new LinearAxis()
            {
                Position = AxisPosition.Bottom
            });

            MyOxyPlotView.Model = model;
  1. Debug the app :

throw an exception:

System.BadImageFormatException
  HResult=0x8007000B
  Message=试图加载格式不正确的程序。 (异常来自 HRESULT:0x8007000B)
  Source=SkiaSharp
  StackTrace:
   at SkiaSharp.SkiaApi.sk_paint_new()
   at SkiaSharp.SKPaint..ctor()
   at OxyPlot.SkiaSharp.SkiaRenderContext..ctor()
   at OxyPlot.SkiaSharp.Wpf.PlotView.CreateRenderContext()
   at OxyPlot.Wpf.PlotViewBase.OnApplyTemplate()
   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.Documents.AdornerDecorator.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.Window.MeasureOverrideHelper(Size constraint)
   at System.Windows.Window.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Interop.HwndSource.SetLayoutSize()
   at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
   at System.Windows.Window.SetRootVisual()
   at System.Windows.Window.SetRootVisualAndUpdateSTC()
   at System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight)
   at System.Windows.Window.CreateSourceWindow(Boolean duringShow)
   at System.Windows.Window.ShowHelper(Object booleanBox)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at SkiaSharpWpf.App.Main()

but I change the .net version to: netcoreapp3.1, debug no throw exception

Platform: WPF,
.NET version: netframework 4.5 or 4.8

<PackageReference Include="OxyPlot.SkiaSharp.Wpf" Version="2.1.0-Preview1" />
@VisualMelon
Copy link
Contributor

This is probably because SkiaSharp has native dependencies, which means you need to be using the appropriate version of the framework (x86/x64) to run it; you can't get away with AnyCpu. You will need to commit to a target-platform for .NET framework.

There is some slightly confused discussion here: #1514 (comment) . You can find an example csproj depending on SkiaSharp here: https://github.com/oxyplot/oxyplot/blob/develop/Source/OxyPlot.SkiaSharp.Tests/OxyPlot.SkiaSharp.Tests.csproj

@mzy666888
Copy link
Author

thanks, it's works.

This is probably because SkiaSharp has native dependencies, which means you need to be using the appropriate version of the framework (x86/x64) to run it; you can't get away with AnyCpu. You will need to commit to a target-platform for .NET framework.

There is some slightly confused discussion here: #1514 (comment) . You can find an example csproj depending on SkiaSharp here: https://github.com/oxyplot/oxyplot/blob/develop/Source/OxyPlot.SkiaSharp.Tests/OxyPlot.SkiaSharp.Tests.csproj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants