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

时间:2019-03-14 16:53:29

标签: xamarin xamarin.forms uwp xamarin.uwp

我正在开发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有所帮助,但我仍然遇到问题。我该怎么做才能使我的应用程序再次运行?

1 个答案:

答案 0 :(得分:4)

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

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

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

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

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

  1. 将UWP项目的最低版本设置为17134或更高版本
  2. 从NuGet安装Win2D.uwp软件包到您的UWP项目