Bug 43694 - StaticResource does not work for x:String and OnPlatform
Summary: StaticResource does not work for x:String and OnPlatform
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.1
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2016-08-24 08:24 UTC by Karol S
Modified: 2017-07-05 06:17 UTC (History)
7 users (show)

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

Repro project (280.58 KB, application/x-zip-compressed)
2017-01-09 19:55 UTC, E.Z. Hart [MSFT]

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:

Description Karol S 2016-08-24 08:24:13 UTC
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
      <x:String x:Key="Light">
        <OnPlatform x:TypeArguments="x:String">
          <OnPlatform.WinPhone>/Assets/Fonts/OpenSans-Light.ttf#Open Sans</OnPlatform.WinPhone>

This code results in error: Sequence contains no elements

Happens both in App.xaml.cs and page xamls.

Works for double resource:
      <x:Double x:Key="FontSize">
        <OnPlatform x:TypeArguments="x:Double">

And the code works also well if nested inside a style:
       <Style x:Key="BaseLabel" TargetType="Label" BasedOn="Label">
        <Setter Property="FontFamily" >
          <x:String x:Key="Light">
            <OnPlatform x:TypeArguments="x:String">
              <OnPlatform.WinPhone>/Assets/Fonts/OpenSans-Light.ttf#Open Sans</OnPlatform.WinPhone>

So the problem is only with string static resource.
Comment 1 Karol S 2016-08-24 08:27:48 UTC
I incorrectly pasted the last code sample, but after removing x:String parts it compiles
Comment 2 E.Z. Hart [MSFT] 2017-01-09 19:55:43 UTC
Created attachment 19139 [details]
Repro project
Comment 3 Stephane Delcroix 2017-01-25 09:49:24 UTC
@ez: this repro can't be used... and it's 43694, not 43964 :P
Comment 4 Stephane Delcroix 2017-01-25 11:56:52 UTC
this is too far of a stretch... <x:String> markup (and other markup for types primitives is meant to create a string from a string literal, and not from another element that might be a string.

the example you show using x:Double doesn't work. It only fails silently...

you can fix your code by declaring it like this:

    <OnPlatform x:Key="Light" x:TypeArguments="x:String">
      <OnPlatform.WinPhone>/Assets/Fonts/OpenSans-Light.ttf#Open Sans</OnPlatform.WinPhone>

I'v changed the Xaml parser and compiler so it throws a meaningful exception instead of an InvalidOperationException. Note that this will throw for your <x:Double> example now: https://github.com/xamarin/Xamarin.Forms/pull/714
Comment 5 Stephane Delcroix 2017-02-02 10:22:25 UTC
this will be fixed in 2.3.5-pre1
Comment 6 faceoffers28 2017-06-15 15:07:46 UTC
I'm in the process of making the OnPlatform changes to my XAML as part of the 2.3.4 upgrade. Are you saying that making the change to code like this will not cause an error because it is wrapped in a Style? I'm running

<Style x:Key="ActivityIndicatorStyle" TargetType="ActivityIndicator">
        <Setter Property="Color">
        	<OnPlatform x:TypeArguments="x:String"
              WinPhone="Blue" />

Seems like x:TypeArguments="x:Double" are OK based on Karol's comment.

What about x:TypeArguments="GridLength"?

Comment 7 Neha Kharbade 2017-07-05 06:17:14 UTC

As attached repo sample is of different bug. 

Could you please provide me test steps to verify this bug. Your help would be appreciated.