Bug 25626 - Exception: Assign Font on Label -> Invalid cross-thread access.
Summary: Exception: Assign Font on Label -> Invalid cross-thread access.
Status: RESOLVED INVALID
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-12-27 06:57 UTC by Thetyne
Modified: 2015-01-17 08:10 UTC (History)
3 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 INVALID

Description Thetyne 2014-12-27 06:57:19 UTC
Xamarin.Forms 1.3.1.6294-pre1
WinPhone 8.1 (lumia 930)

Xaml Code:
<?xml version="1.0" encoding="utf-8" ?>
<BasePage xmlns="http://xamarin.com/schemas/2014/forms"
					xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
					x:Class="XXX.XXX.MessageView">
  <Label Text="{Binding Title}" Font="10"/>
</BasePage>


Exception StackTrace:
   at MS.Internal.XcpImports.CheckThread()
   at MS.Internal.XcpImports.GetValue(IManagedPeerBase managedPeer, DependencyProperty property)
   at System.Windows.Application.get_Resources()
   at Xamarin.Forms.WP8PlatformServices.GetNamedSize(NamedSize size, Type targetElementType, Boolean useOldSizes)
   at Xamarin.Forms.Device.GetNamedSize(NamedSize size, Type targetElementType, Boolean useOldSizes)
   at Xamarin.Forms.Device.GetNamedSize(NamedSize size, Type targetElementType)
   at Xamarin.Forms.Device.GetNamedSize(NamedSize size, Element targetElement)
   at Xamarin.Forms.Label.<.cctor>b__1(BindableObject bindable)
   at Xamarin.Forms.BindableObject.GetOrCreateContext(BindableProperty property)
   at Xamarin.Forms.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes)
   at Xamarin.Forms.BindableObject.SetValue(BindableProperty property, Object value, Boolean fromStyle, Boolean checkAccess)
   at Xamarin.Forms.BindableObject.SetValue(BindableProperty property, Object value)
   at Xamarin.Forms.Label.set_FontSize(Double value)
   at Xamarin.Forms.Label.FontStructPropertyChanged(BindableObject bindable, Object oldValue, Object newValue)
   at Xamarin.Forms.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent)
   at Xamarin.Forms.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes)
   at Xamarin.Forms.BindableObject.SetValue(BindableProperty property, Object value, Boolean fromStyle, Boolean checkAccess)
   at Xamarin.Forms.BindableObject.SetValue(BindableProperty property, Object value)
   at Xamarin.Forms.Xaml.ApplyPropertiesVisitor.SetPropertyValue(Object xamlelement, XmlName propertyName, Object value, BindableObject rootElement, INode node, HydratationContext context, IXmlLineInfo lineInfo)
   at Xamarin.Forms.Xaml.ApplyPropertiesVisitor.Visit(ValueNode node, INode parentNode)
   at Xamarin.Forms.Xaml.ValueNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Xamarin.Forms.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Xamarin.Forms.Xaml.RootNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Xamarin.Forms.Xaml.XamlLoader.Load(BindableObject view, String xaml)
   at Xamarin.Forms.Xaml.XamlLoader.Load(BindableObject view, Type callingType)
   at Xamarin.Forms.Xaml.Extensions.LoadFromXaml[TView](TView view, Type callingType)
   at Cylande.Retail.MobilityCore.View.Divers.MessageView.InitializeComponent()
   at Cylande.Retail.MobilityCore.View.Divers.MessageView..ctor(MessageViewModelBase viewModel)
   at Cylande.Retail.MobilityCore.ViewModel.Divers.MessageViewModel.AfficheEcran()
Comment 1 Thetyne 2014-12-27 10:07:00 UTC
Produce error when i use

Device.BeginInvokeOnMainThread(() =>
                {
                    Navigation.PushAsync(this);
                });

or

await Task.Run (() => {}).ContinueWith (async t => {
   await Navigation.PushAsync(this);
}, uiTaskSheduler);
Comment 2 Jason Smith [MSFT] 2015-01-16 21:21:25 UTC
We will need to see more code unfortauntely. It appears your are somehow inflating the XAML on a thread which results in this error. I would need to see the code more closely to see how, or need a reproduction case.
Comment 3 Thetyne 2015-01-17 08:10:17 UTC
Ok, i check. my error it's:

Task.Run(() =>
{
    Page2 page2 = new Page2();
    Device.BeginInvokeOnMainThread(() =>
    {
        Navigation.PushAsync(page2);
    });
});

i change to create Page2 to main thread and it's Work.
Task.Run(() =>
{
    Device.BeginInvokeOnMainThread(() =>
    {
        Page2 page2 = new Page2();
        Navigation.PushAsync(page2);
    });
});