I started to get XLS0501 errors in Visual Studio saying that this property is set more than once (OnPlatform items). It isn't. The project compiles and runs.
<Image>
<Image.Source>
<OnPlatform x:TypeArguments="FileImageSource" Default="ic_cancel.png">
<On Platform="UWP" Value="Resources/ic_cancel.png" />
</OnPlatform>
</Image.Source>
</Image>
No error message.
The newer markup extension doesn't have this problem, it has another one:
<ToolbarItem ... Icon="{OnPlatform Default='ic_cart.png' UWP='Resources/ic_cart.png'}" />
Update: the two strange Expected errors come if the comma is missing between the values:
Icon="{OnPlatform Default='ic_cart.png' UWP='Resources/ic_cart.png'}"
rather than
Icon="{OnPlatform Default='ic_cart.png', UWP='Resources/ic_cart.png'}"
Actually, the comma doesn't seem to be absolutely required but if so, the error message could be a tad more to the point. :-)
@StephaneDelcroix Can you confirm that this is just a VS IntelliSense / false-flag error and not something that will be a problem in the compiled code?
I can't switch everything to the new in-lined approach because some are standalone OnPlatform instances in ResourceDictionary.
I'm seeing similar with in App.xaml with:
<OnPlatform x:TypeArguments="x:String" x:Key="Condensed">
<On Platform="Android" Value="AvenirNextLTPro-Cn.otf#AvenirNext LT Pro Cn" />
<On Platform="iOS" Value="AvenirNext LT Pro Cn" />
</OnPlatform>
VS2017 15.8 / Xam Forms 3.2.0.839982.
Was also fine in the last 3.1.x release.
/cc @mgoertz-msft
Assuming ping to mgoertz implies this is external.
@StephaneDelcroix @LanceMcCarthy @jamsoft
Still an issue as of October 10, 2018
VS2017 15.8.8
Xamarin forms 3.3.0.912540
@tzviszlar That is deprecated code (from XF 2.5 and older) and is not a good workaround.
@LanceMcCarthy you are correct! I didn't even notice I circle back to the old syntax.... Thank you
@CasNouwens I had the same errors but fixed it by wrapping the <On Platform/>
statements in a <OnPlatform.Platforms>
block:
<OnPlatform.Platforms>
<On Platform="Android" Value="18" />
<On Platform="iOS" Value="20" />
</OnPlatform.Platforms>
Syntax has changed. This works..
<ResourceDictionary>
<OnPlatform x:TypeArguments="x:String" x:Key="BoldFont" Android="OpenSans-Bold.ttf#Open Sans" iOS="OpenSans-Bold"/>
<OnPlatform x:TypeArguments="x:String" x:Key="NormalFont" Android="OpenSans-Regular.ttf#Open Sans" iOS="OpenSans-Regular"/>
..
@yunustunahan see my comment above, that is deprecated. It uses the platform enum.
You should instead only use string identifiers for the platform names.
@LanceMcCarthy , oh I see, so its just an intellisence error.
Because I had coded it as the way you metioned but the VS editor was underlining it.
Thanks Lance..
The message "default has been set more than one" usually happens when the property is only expecting one value.
The workaround from @nauderoode is a great one because you explicitly set the Platforms property, which does expect a collection.
what if i want to put view in onplatform ? in the previous releases it works fine now it got me default is set more than once
i tried this but didn't work
<OnPlatform.Platforms>
<On Platform="Android"><Button Text="{Binding ProductQty, Mode=TwoWay}" IsEnabled="False" BackgroundColor="Transparent" FontSize="Small" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" FontAttributes="Bold" WidthRequest="40" HeightRequest="50" TextColor="Black"> </Button>
</On>
<On Platform="iOS">
<Label Text="{Binding ProductQty, Mode=TwoWay}" VerticalTextAlignment="Center" FontSize="Small" HorizontalTextAlignment="Center" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" FontAttributes="Bold" WidthRequest="40" HeightRequest="50" TextColor="Black"></Label>
</On>/OnPlatform.Platforms>
You forgot to set the Value property
<OnPlatform.Platforms>
<On Platform="Android">
<On.Value>
<Button />
sorry can you post sample ?
Accorrding to your workround this not works for me ,
XLS0415 The attachable property 'Platforms' was not found in type 'OnPlatform'.
<OnPlatform.Platforms>
<On Platform="Android">
<On.Value>
<Button
</On.Value>
</On>
<On Platform="iOS">
<On.Value>
<Label
</On.Value>
</On>
</OnPlatform.Platforms>
@amrkamal1993
Sometimes you need to do a build before believing what IntelliSense errors tell you (especially in Xamarin.Forms XAML). Even then, you can ignore the "Default is set more than once" or the "Platforms is not an attachable property" because they're false errors (_which is the point of this open issue, the language service should not be flagging as error_).
If you are not able to build, in the Errors output window, make sure the drop down is Build Only instead of Build + IntelliSense, that way you'll see the legitimate error preventing the build.
This is valid XAML, that compiles and runs:
<ContentView>
<OnPlatform x:TypeArguments="View">
<OnPlatform.Platforms>
<On Platform="Android">
<On.Value>
<Button Text="I'm an Android Button" />
</On.Value>
</On>
<On Platform="iOS">
<On.Value>
<Button Text="I'm an iOS Button" />
</On.Value>
</On>
<On Platform="UWP">
<On.Value>
<Button Text="I'm a UWP Button" />
</On.Value>
</On>
</OnPlatform.Platforms>
</OnPlatform>
</ContentView>
I've found a simpler inline solution that doesn't show / give any errors:
<OnPlatform x:Key="RegularFont"
x:TypeArguments="x:String"
Android="Android Font"
iOS="iOS Font"
WinPhone="WinPhone Font" />
That's not the point. There have been three various syntax solutions to this. The one you mention is the oldest of them all. Then came the second (this one has bugs now). Then came the third. The fact the the very first one still works doesn't change the fact that the second one started to show buggy behavior and needs to be fixed. Yes, both the first and the third syntax work all right, we know that.
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/get-started/hello-xamarin-forms/quickstart?pivots=windows
I step by step with this tutorial,then I meet this problem too.
the positon is at
- In MainPage.xaml, remove all of the template code and replace it with the following code. This code declaratively defines the user interface for the page:
is this tutorial need to update?
Xamarin.Forms 3.3.0.967583
VS2017 15.9.2
this just Visual Studio tip error , but in fact it can run,you just nedd to close all files then build
you can look the demo that I write ,
https://github.com/DHclly/IceDog.Xamarin/tree/develop/src/IceDog.Xamarin.Phoneword
In my case this was a build error. The project didn´t lunch at all.
None of the suggestions here helped.
I deleted .vs folder and then I run git clean -xdf
on the project root folder.
Everything went back to normal without code changes. VS does not see any issues now on the OnPlatform
declarations.
This is how I´m using it:
<OnPlatform x:Key="GtWalsheimProRegular" x:TypeArguments="x:String">
<On Platform="Android" Value="gt-walsheim-pro-regular-web.ttf#GTWalsheimProRegular"/>
<On Platform="iOS" Value="GTWalsheimProRegular"/>
</OnPlatform>
Update: never mind. This is now happening even when I clean the project. Stuck here... I can´t build the project
Update 2: I fixed the issue completely by removing LiveXAML nuget from my project
You don't seem to use any Default at all, so this might be the reason.
@CasNouwens
if you use the Xamarin.Forms 3.3.0.967583(3.3.x) , you can try to close all file then build , maybe you can build success.
This is indeed a bug in the XAML language service and it was exposed with the introduction of the OnPlatformExtension MarkupExtension type last year. For <OnPlatform …/>
the type resolution logic would first look for OnPlatform, then OnPlatformExtension, and then OnPlatform`1.
That worked just fine as long as there were no generic types and MarkupExtensions with the same base name, but that's no longer the case in Xamarin Forms these days. We will get this fixed in Visual Studio 2019 (Dev16).
This worked..
<OnPlatform
x:TypeArguments="Thickness"
Android="16,16,16,4"
Default="16,16,16,4"
iOS="16,24,16,4" />
@chinthaka24 That is deprecated code, it uses the enum values instead of the string platform name.
There is nothing wrong with the "Default is set more than once" message, it's just a language service error message that is not really an error. It's a false flag that will be resolved in VS2019.
I strongly recommend that you do not use that code as it will stop working when the enums are removed.
Is there any reason for VS2017 not recognizing x:TypeArguments
parameter in any of the three OnPlatform syntaxes?
Should I file a separate issue for that?
That worked just fine as long as there were no generic types and MarkupExtensions with the same base name, but that's no longer the case in Xamarin Forms these days. We will get this fixed in Visual Studio 2019 (Dev16).
@mgoertz-msft does this mean the issue will not be fixed in VS2017 15.9.x?
Correct, at this point we only port fixes for serious issues affecting a lot of people back to VS 2017. The only way to potentially make that happen would be to create a VS feedback ticket and gather a lot of upvotes for it on the developer community site.
If you continue to experience this issue, please report it via the send feedback option within Visual Studio. Thank you!
If you continue to experience this issue
I no longer get an error message/error indicator in XAML editor in VS2017 only a tooltip indicating the message when I hover over the XAML and this no longer confuses me.
Most helpful comment
This is indeed a bug in the XAML language service and it was exposed with the introduction of the OnPlatformExtension MarkupExtension type last year. For
<OnPlatform …/>
the type resolution logic would first look for OnPlatform, then OnPlatformExtension, and then OnPlatform`1.That worked just fine as long as there were no generic types and MarkupExtensions with the same base name, but that's no longer the case in Xamarin Forms these days. We will get this fixed in Visual Studio 2019 (Dev16).