Xamarin.UWP应用程序无法启动,因为无法加载“Microsoft.Graphics.Canvas.UI.Xaml.CanvasImageSource”

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Xamarin.UWP应用程序无法启动,因为无法加载“Microsoft.Graphics.Canvas.UI.Xaml.CanvasImageSource”相关的知识,希望对你有一定的参考价值。

我正在开发android / ios / UWP Xamarin.Forms应用程序。最近几周我主要使用Android / iOS应用程序。现在,我想在UWP中再次启动我的应用程序并获取错误:

System.TypeLoadException
  HResult=0x80131522
  Message=Could not find Windows Runtime type 'Microsoft.Graphics.Canvas.UI.Xaml.CanvasImageSource'.
  Source=Xamarin.Forms.Platform.UAP
  StackTrace:
   at Xamarin.Forms.Platform.UWP.ImageRenderer.GetDesiredSize(Double widthConstraint, Double heightConstraint)
   at Xamarin.Forms.Platform.UWP.Platform.GetNativeSize(VisualElement element, Double widthConstraint, Double heightConstraint)
   at Xamarin.Forms.Platform.UWP.WindowsBasePlatformServices.GetNativeSize(VisualElement view, Double widthConstraint, Double heightConstraint)
   at Xamarin.Forms.VisualElement.OnSizeRequest(Double widthConstraint, Double heightConstraint)
   at Xamarin.Forms.Image.OnSizeRequest(Double widthConstraint, Double heightConstraint)
   at Xamarin.Forms.VisualElement.OnMeasure(Double widthConstraint, Double heightConstraint)
   at Xamarin.Forms.VisualElement.GetSizeRequest(Double widthConstraint, Double heightConstraint)
   at Xamarin.Forms.VisualElement.Measure(Double widthConstraint, Double heightConstraint, MeasureFlags flags)
   at Xamarin.Forms.StackLayout.CalculateNaiveLayout(LayoutInformation layout, StackOrientation orientation, Double x, Double y, Double widthConstraint, Double heightConstraint)
   at Xamarin.Forms.StackLayout.CalculateLayout(LayoutInformation layout, Double x, Double y, Double widthConstraint, Double heightConstraint, Boolean processExpanders)
   at Xamarin.Forms.StackLayout.OnSizeRequest(Double widthConstraint, Double heightConstraint)
   at Xamarin.Forms.VisualElement.OnMeasure(Double widthConstraint, Double heightConstraint)
   at Xamarin.Forms.VisualElement.GetSizeRequest(Double widthConstraint, Double heightConstraint)
   at Xamarin.Forms.Layout.GetSizeRequest(Double widthConstraint, Double heightConstraint)
   at Xamarin.Forms.VisualElement.Measure(Double widthConstraint, Double heightConstraint, MeasureFlags flags)
   at Xamarin.Forms.ScrollView.OnSizeRequest(Double widthConstraint, Double heightConstraint)
   at Xamarin.Forms.VisualElement.OnMeasure(Double widthConstraint, Double heightConstraint)
   at Xamarin.Forms.VisualElement.GetSizeRequest(Double widthConstraint, Double heightConstraint)
   at Xamarin.Forms.Layout.GetSizeRequest(Double widthConstraint, Double heightConstraint)
   at Xamarin.Forms.VisualElement.Measure(Double widthConstraint, Double heightConstraint, MeasureFlags flags)
   at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion(VisualElement child, Rectangle region)
   at Xamarin.Forms.Page.LayoutChildren(Double x, Double y, Double width, Double height)
   at Xamarin.Forms.Page.UpdateChildrenLayout()
   at Xamarin.Forms.Page.OnSizeAllocated(Double width, Double height)
   at RA_Krypt.MainPage.OnSizeAllocated(Double width, Double height) in C:\Users\Christian\source\repos\Xamarin_RaKrypt\RA-Krypt\RA-Krypt\MainPage.xaml.cs:line 27
   at Xamarin.Forms.Page.OnChildMeasureInvalidated(VisualElement child, InvalidationTrigger trigger)
   at Xamarin.Forms.Page.OnChildMeasureInvalidated(Object sender, EventArgs e)
   at Xamarin.Forms.VisualElement.InvalidateMeasureInternal(InvalidationTrigger trigger)
   at Xamarin.Forms.VisualElement.set_IsNativeStateConsistent(Boolean value)
   at Xamarin.Forms.Platform.UWP.VisualElementRenderer`2.OnControlLoaded(Object sender, RoutedEventArgs args)

我的应用程序根本没有启动。我重建了我的项目并重新启动了我的计算机,这有时可以帮助Xamarin,但我仍然卡住了。我需要做些什么才能让我的应用再次运行?

答案

已报告并修复此错误,请参阅this issue on GitHub。该修复程序将包含在即将发布的Xamarin.Forms中。

目前有解决方法。确保安装了最新版本的Xamarin.Forms。然后:

如果您需要支持Fall Creators Update(SDK 16299)

  1. 确保项目的最小版本设置为至少Fall Creators Update(16299)
  2. 将Nuzet的Win2D.uwp软件包安装到您的UWP项目中
  3. <DisableWin2DPlatformCheck>true</DisableWin2DPlatformCheck>添加到UWP项目的csproj

如果你可以支持最低版本SDK 17134

  1. 将UWP项目的最小版本设置为17134或更新版本
  2. 将Nuzet的Win2D.uwp软件包安装到您的UWP项目中

以上是关于Xamarin.UWP应用程序无法启动,因为无法加载“Microsoft.Graphics.Canvas.UI.Xaml.CanvasImageSource”的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Xamarin UWP 中更改 CommandBar Title 字体大小

Xamarin UWP:视频播放器组件似乎不适用于打开 .NET Native 工具链的编译

由于 Xamarin UWP 项目中的 Xamarin.CarouselView,UWP 应用程序崩溃

如何更改 Xamarin UWP 应用名称

如何在 Xamarin.UWP 应用程序中实现 LongPress?

应用程序的 Xamarin UWP 图标资产