Bug 31088 - FontSize = Font.SystemFontOfSize(NamedSize.Large).FontSize; // crashes in WP
Summary: FontSize = Font.SystemFontOfSize(NamedSize.Large).FontSize; // crashes in WP
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows ()
Version: 1.4.2
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-06-13 11:25 UTC by Niels
Modified: 2015-06-16 14:15 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Niels 2015-06-13 11:25:57 UTC
I got an "obsolete" warning in VS on the following line of code:

Font = Font.SystemFontOfSize(NamedSize.Large),

So I changed it to:

FontSize = Font.SystemFontOfSize(NamedSize.Large).FontSize

This caused the following error on Windows Phone and prevented a page from loading:

{System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
   at Xamarin.Forms.Platform.WinPhone.FontExtensions.ApplyFont(TextBlock self, Font font)
   at Xamarin.Forms.Platform.WinPhone.LabelRenderer.UpdateFont(TextBlock textBlock)
   at Xamarin.Forms.Platform.WinPhone.LabelRenderer.OnElementChanged(ElementChangedEventArgs`1 e)
   at Xamarin.Forms.Platform.WinPhone.VisualElementRenderer`2.SetElement(VisualElement element)
   at Xamarin.Forms.Platform.WinPhone.RendererFactory.GetRenderer(VisualElement view)
   at Xamarin.Forms.Platform.WinPhone.VisualElementPackager.HandleChildAdded(Object sender, ElementEventArgs e)
   at Xamarin.Forms.Element.OnChildAdded(Element child)
   at Xamarin.Forms.Layout.OnInternalAdded(View view)
   at Xamarin.Forms.Layout.InternalChildrenOnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
   at System.Collections.ObjectModel.Collection`1.Add(T item)
   at Xamarin.Forms.ObservableWrapper`2.Add(TRestrict item)
   at FormsApp.Pages.ResultsFilterPage.<SetFilter>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at FormsApp.Pages.ResultsFilterPage.<ResultsFilterPage_Appearing>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__3(Object state)}
Comment 1 Stephane Delcroix 2015-06-15 04:44:29 UTC
could you try this as workaround ?

    FontSize = Device.GetNamedSize (NamedSize.Large, label);
Comment 2 Jason Smith [MSFT] 2015-06-16 13:39:21 UTC
The workaround Stephane posted is the correct workaround. Unfortunately the code you posted could not be made to work without a behavioral change.
Comment 3 Niels 2015-06-16 14:15:45 UTC
This works, thanks! Maybe it is possible to throw an error on my previous code, because the page doesn't load without breaking or anything. I spent over an hour to search for the cause.