Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setter showing a Build Error when using XAML OnPlatform Markup Extension #12064

Closed
vsfeedback opened this issue Dec 13, 2022 · 13 comments · Fixed by #17061
Closed

Setter showing a Build Error when using XAML OnPlatform Markup Extension #12064

vsfeedback opened this issue Dec 13, 2022 · 13 comments · Fixed by #17061
Assignees
Labels
area-xaml XAML, CSS, Triggers, Behaviors fixed-in-8.0.10 fixed-in-8.0.14 fixed-in-8.0.40 fixed-in-9.0.0-preview.2.10247 fixed-in-9.0.0-preview.2.10293 p/1 Work that is critical for the release, but we could probably ship without partner/cat 😻 Client CAT Team s/triaged Issue has been reviewed t/bug Something isn't working
Milestone

Comments

@vsfeedback
Copy link

vsfeedback commented Dec 13, 2022

This issue has been moved from a ticket on Developer Community.


[severity:I'm unable to use this version]
If I try to use an On Platform XAML Markup Extension and Build the project I get an error, "Missing Value For Setter". This does not stop the project running in debug mode, where the error disappears from the list.
However this does stop Publishing because the project will not Build (Failed to create App archive 'ProjectPlannerMAUI'. Please ensure your project builds before archiving it.).
The following shows a snippet where the first Setter is OK but the second Setter gives an error:

Error Position 43:18. Missing Value for Setter ProjectPlannerMAUI C:\VSProjects\ProjectPlannerMAUI\ProjectPlannerMAUI\App.xaml 43

<Style x:Key="controlStyleSmallAndroid" TargetType="Label">
                <Setter Property="FontSize" Value="18"/>
            </Style>
            <Style x:Key="controlStyleLargeAndroid" TargetType="Label">
                <Setter Property="FontSize" Value="{OnPlatform iOS=18, Android=24, WinUI=18}"/>
            </Style>

Original Comments

Feedback Bot on 11/30/2022, 06:35 PM:

(private comment, text removed)

Glenn Taylor on 12/2/2022, 06:23 AM:

(private comment, text removed)


Original Solutions

(no solutions)

@jsuarezruiz jsuarezruiz added area-xaml XAML, CSS, Triggers, Behaviors area-tooling XAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debugging labels Dec 14, 2022
@GDT48
Copy link

GDT48 commented Dec 14, 2022

Don't understand this. This is now flagged as Closed - Duplicate. Does this mean the reported issue is closed? Without a reply or solution? Not sure what the added area/Xaml </> and area/tooling means.

@jsuarezruiz jsuarezruiz added this to the Backlog milestone Dec 14, 2022
@ghost
Copy link

ghost commented Dec 14, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@jsuarezruiz
Copy link
Contributor

cc @StephaneDelcroix

@Eilon Eilon removed the area-tooling XAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debugging label Jan 20, 2023
@mikeparker104 mikeparker104 added the partner/cat 😻 Client CAT Team label Mar 8, 2023
@Hooterr
Copy link

Hooterr commented Jul 28, 2023

This issue still exists. If you use {OnPlatform} in a app-level resource dictionary it causes build error in Visual Studio on windows.
Weirdly enough on VS for mac it works fine...
cc: @jsuarezruiz

@samhouts samhouts added t/bug Something isn't working p/1 Work that is critical for the release, but we could probably ship without labels Jul 31, 2023
@samhouts samhouts modified the milestones: Backlog, .NET 8 GA Aug 16, 2023
@jinxinjuan jinxinjuan added s/triaged Issue has been reviewed s/no-repro Can no longer be reproduced on latest labels Aug 22, 2023
@jinxinjuan
Copy link
Collaborator

Could you provide a sample project to repro this issue? Also other more info? Thanks.

@GDT48
Copy link

GDT48 commented Aug 22, 2023

I have created a small sample project available at https://github.com/GDT48/SetterError
Added a Picker to MainPage.
Added a Style to App.XML which contains a conditional property.
Project runs in Debug without issue.
However will not build, errors:
Error Position 14:18. Missing Value for Setter
Error Position 14:18. Missing Value for Setter

@Hooterr
Copy link

Hooterr commented Aug 22, 2023

@GDT48 looks like the repo is private.

@GDT48
Copy link

GDT48 commented Aug 23, 2023

Thanks, my apologies. I have now made public.

@BretJohnson BretJohnson self-assigned this Aug 24, 2023
@BretJohnson
Copy link
Member

BretJohnson commented Aug 24, 2023

The test project targets iOS (and thus builds for it, even on Windows), but OnPlatform just specifies values for Android and WinUI, not iOS. Adding iOS to OnPlatform, or adding a Default value, looks to make it work.
@GDT48 - That should fix things for you, but please let us know if there's another issue here you see.
Meanwhile, on our side, we should really update the error message to be more specific on what's missing, to be less confusing. I'll take a look at fixing that.

@GDT48
Copy link

GDT48 commented Aug 25, 2023 via email

@BretJohnson BretJohnson removed the s/no-repro Can no longer be reproduced on latest label Aug 25, 2023
@BretJohnson
Copy link
Member

Update: I looked more at OnPlatform functionality in Xamarin.Forms and confirmed that when the platform doesn't match, there should just be no property set, not an error. So while setting a default is a workaround, we really should fix this. Looking at that now.

BretJohnson added a commit that referenced this issue Aug 29, 2023
When OnPlatforfm is used for a Setter value, and there's no match for the
current platform, fix so that the property isn't set (same behavior as Xamarin.Forms).
Previously, XamlC would report a "Missing Value For Setter" error when this happens
and non-compiled XAML would crash with an NRE. This PR contains fixes for both,
ensuring the XAML compiler doesn't show an error, then ensuring it doesn't crash
at runtime.

Fixes #12064
@BretJohnson
Copy link
Member

Another update: With this issue, when XAML is compiled it results in the "Missing Value For Setter" XamlC error, but when XAML compilation is turned off, the result is a runtime NullReferenceException crash. So that's all the more reason to fix it, which my PR here #17061 does.

@mtarros
Copy link

mtarros commented Sep 28, 2023

I have created a small sample project available at https://github.com/GDT48/SetterError Added a Picker to MainPage. Added a Style to App.XML which contains a conditional property. Project runs in Debug without issue. However will not build, errors: Error Position 14:18. Missing Value for Setter Error Position 14:18. Missing Value for Setter

Try removing the ResourceDictionary tags in App.XML and see if that fixes your issue.

I have a similar issue were debug mode runs just fine but in release build I get missing key errors and removing the ResourceDictionary tags solved my issue.

@PureWeen PureWeen modified the milestones: .NET 8 SR2, .NET 8 SR3 Nov 22, 2023
rmarinho pushed a commit that referenced this issue Feb 12, 2024
* Fix OnPlatform + Setter when no match for current platform

When OnPlatforfm is used for a Setter value, and there's no match for the
current platform, fix so that the property isn't set (same behavior as Xamarin.Forms).
Previously, XamlC would report a "Missing Value For Setter" error when this happens
and non-compiled XAML would crash with an NRE. This PR contains fixes for both,
ensuring the XAML compiler doesn't show an error, then ensuring it doesn't crash
at runtime.

Fixes #12064

* Swtich to device tests for OnPlatform

* Remove test screenshot, no longer used
@github-actions github-actions bot locked and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-xaml XAML, CSS, Triggers, Behaviors fixed-in-8.0.10 fixed-in-8.0.14 fixed-in-8.0.40 fixed-in-9.0.0-preview.2.10247 fixed-in-9.0.0-preview.2.10293 p/1 Work that is critical for the release, but we could probably ship without partner/cat 😻 Client CAT Team s/triaged Issue has been reviewed t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.