Xamarin.forms: [UWP] StyleSheet Source runtime error

Created on 25 Jan 2018  路  9Comments  路  Source: xamarin/Xamarin.Forms

Description

Added a stylesheet and at runtime on UWP I get the error below.

Steps to Reproduce

  1. New project, .NET Standard library
  2. Add css file and set build type to embedded resource
  3. Add some css
  4. Add to MainPage.xaml (or other)
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:Latest"
             x:Class="Latest.MainPage">
    <ContentPage.Resources>
        <StyleSheet Source="Main.css"/>
    </ContentPage.Resources>

    <Label Text="Welcome to Xamarin.Forms!" 
           VerticalOptions="Center" 
           HorizontalOptions="Center" />

</ContentPage>

Main.css:

^ContentPage {
    background-color: #ff6a00;
}

Expected Behavior

I see an orange bg.

Actual Behavior

Runtime error.

Xamarin.Forms.Xaml.XamlParseException HResult=0x80131500 Message=Position 7:21. Cannot assign property "Source": Property does not exist, or is not assignable, or mismatching type between value and property Source=Xamarin.Forms.Xaml StackTrace: at Xamarin.Forms.Xaml.ApplyPropertiesVisitor.SetPropertyValue(Object xamlelement, XmlName propertyName, Object value, Object rootElement, INode node, HydrationContext 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.Visit(RootNode rootnode, HydrationContext visitorContext) at Xamarin.Forms.Xaml.XamlLoader.Load(Object view, String xaml) at Xamarin.Forms.Xaml.XamlLoader.Load(Object view, Type callingType) at Xamarin.Forms.Xaml.Extensions.LoadFromXaml[TXaml](TXaml view, Type callingType) at Latest.MainPage.InitializeComponent() in C:\Users\dave\Source\Repos\Latest\Latest\Latest\obj\Debug\netstandard2.0\MainPage.xaml.g.cs:line 21 at Latest.MainPage..ctor() in C:\Users\dave\Source\Repos\Latest\Latest\Latest\MainPage.xaml.cs:line 14 at Latest.App..ctor() in C:\Users\dave\Source\Repos\Latest\Latest\Latest\App.xaml.cs:line 16 at Latest.UWP.MainPage..ctor() in C:\Users\dave\Source\Repos\Latest\Latest\Latest.UWP\MainPage.xaml.cs:line 24 at Latest.UWP.Latest_UWP_XamlTypeInfo.XamlTypeInfoProvider.Activate_4_MainPage() in C:\Users\dave\Source\Repos\Latest\Latest\Latest.UWP\obj\x86\Debug\XamlTypeInfo.g.cs:line 255 at Latest.UWP.Latest_UWP_XamlTypeInfo.XamlUserType.ActivateInstance() in C:\Users\dave\Source\Repos\Latest\Latest\Latest.UWP\obj\x86\Debug\XamlTypeInfo.g.cs:line 476

Basic Information

Repro Project

Latest.zip

CSS Xaml </> netstandard UWP bug

Most helpful comment

That was a lot of hoops to jump through to change one line of code, but it worked!

  • I downloaded and built 3.0.0
  • Removed Xamarin 3.0.0 Pre3 from my solution and added 9.9.1 from my local nuget
  • Confirmed that the exception still occurred.
  • Applied the attribute and rebuilt as version 9.9.2 and upgraded
  • Ran the project again and it worked OK!

All 9 comments

Confirmed it works on Android in this same solution fwiw.

Inline css worked on UWP.

<StyleSheet>
            <![CDATA[
            ^contentpage {
                background-color: blue;
            }
        ]]>
        </StyleSheet>

works with XamlC on

Is vNext+1 version 3? This is a blocker for using CSS in UWP, could it be moved up to version 3 and a pre-4 built?

Thanks!

@stevehurcombe
does the fix in #1657 works for you ? I haven't had time yet to come back to actually testing it

I'm afraid I don't know. If there is an "easy" way to get a build with it in I'd be happy to try it.

This is a green field project, so there's not much other code to mask things!

Should I grab it from here? I know that's got everything else in it too...

https://myget.org/feed/xamarinforms-ci/package/nuget/Xamarin.Forms

no, the fix isn't present in any released package

OK, so would I be right in thinking that I can download the branch labelled 3.0.0, apply this code change (looks like a one liner) and I'll have the right build?

That was a lot of hoops to jump through to change one line of code, but it worked!

  • I downloaded and built 3.0.0
  • Removed Xamarin 3.0.0 Pre3 from my solution and added 9.9.1 from my local nuget
  • Confirmed that the exception still occurred.
  • Applied the attribute and rebuilt as version 9.9.2 and upgraded
  • Ran the project again and it worked OK!
Was this page helpful?
0 / 5 - 0 ratings

Related issues

sonic1015 picture sonic1015  路  3Comments

simontocknell picture simontocknell  路  3Comments

Papirosnik picture Papirosnik  路  3Comments

joseluisct picture joseluisct  路  3Comments

deakjahn picture deakjahn  路  3Comments