Xamarin.UWP app doesn't start because 'Microsoft.Graphics.Canvas.UI.Xaml.CanvasImageSource' could not be loaded

0

I'm developing an Android/iOS/UWP Xamarin.Forms app. The last weeks I worked mainly on the Android/iOS apps. Now, I want to start my app again in UWP and get the error:

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)

And my app doesn't start at all. I have rebuilt my project and restarted my computer which sometimes helps with Xamarin but I'm still stuck. What do I need to do to get my app working again?

xamarin
xamarin.forms
uwp
xamarin.uwp
asked on Stack Overflow Mar 14, 2019 by Christian • edited Mar 14, 2019 by Martin Zikmund

1 Answer

7

This bug has been reported and fixed, see this issue on GitHub. The fix will be included in upcoming release of Xamarin.Forms.

For now there are workarounds for it. Make sure you have the latest version of Xamarin.Forms installed. Then:

If you need to support Fall Creators Update (SDK 16299)

  1. Make sure the project has min version set to at least Fall Creators Update (16299)
  2. Install the Win2D.uwp package from NuGet to your UWP project
  3. Add <DisableWin2DPlatformCheck>true</DisableWin2DPlatformCheck> to the UWP project's csproj

If you can support min version SDK 17134

  1. Set UWP project's min version to 17134 or newer
  2. Install the Win2D.uwp package from NuGet to your UWP project
answered on Stack Overflow Mar 14, 2019 by Martin Zikmund • edited Mar 14, 2019 by Martin Zikmund

User contributions licensed under CC BY-SA 3.0