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

[regression/8.0.0-rc.1.9171] Build error in .NET 8 RC1 - "XamlC error XFC0126: Resources in ResourceDictionary require a x:Key attribute" for resources that have a key #17461

Closed
brunck opened this issue Sep 18, 2023 · 12 comments · Fixed by #17733
Assignees
Labels
area-xaml XAML, CSS, Triggers, Behaviors fixed-in-8.0.0-rc.2.9511 Look for this fix in 8.0.0-rc.2.9511 i/regression This issue described a confirmed regression on a currently supported version s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@brunck
Copy link
Contributor

brunck commented Sep 18, 2023

Description

Using version 8.0.100-rc.1.23455.8
Building a .NET MAUI app created using RC1 and VS 2022 preview via File -> New Project and adding the given lines errors with XamlC error XFC0126: Resources in ResourceDictionary require a x:Key attribute.

This appears to be a regression; the same code worked in .NET 8 preview 7.

Steps to Reproduce

  1. Create a File -> New .NET MAUI app
  2. Add these lines to the App.xaml file:
<Color x:Key="LightSmoke">#4FFFFFFF</Color>

<OnPlatform x:Key="EntryBackgroundColor" x:TypeArguments="Color">
    <On Platform="iOS" Value="{StaticResource LightSmoke}" />
    <On Platform="Android" Value="Transparent" />
</OnPlatform>
  1. Build fails with the given error message.

Or, use the solution in the given reproduction repository in the MauiResourceDictionaryBuildError folder.

Link to public reproduction project repository

https://github.com/brunck/reproductions.git

Version with bug

8.0.0-rc.1.9171

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.0-preview.7.8842

Affected platforms

I was not able test on other platforms

Affected platform versions

n/a

Did you find any workaround?

Removing the related lines causes the build to pass.

Relevant log output

No response

@brunck brunck added the t/bug Something isn't working label Sep 18, 2023
@samhouts samhouts added area-xaml XAML, CSS, Triggers, Behaviors potential-regression This issue described a possible regression on a currently supported version., verification pending labels Sep 18, 2023
@samhouts samhouts added this to the .NET 8 GA milestone Sep 18, 2023
@samhouts samhouts changed the title Build error in .NET 8 RC1 - "XamlC error XFC0126: Resources in ResourceDictionary require a x:Key attribute" for resources that have a key [regression/8.0.0-rc.1.9171] Build error in .NET 8 RC1 - "XamlC error XFC0126: Resources in ResourceDictionary require a x:Key attribute" for resources that have a key Sep 19, 2023
@tentom
Copy link

tentom commented Sep 19, 2023

I get this same issue if I try to use in my App.Xaml file.
Error XFC0126: Resources in ResourceDictionary require a x:Key attribute. (XFC0126) (AppName) XamlC

But it seems to work if I do use a static resource as the value as the following works:

<OnPlatform x:Key="MediumFontFamily"
                    x:TypeArguments="x:String"
                    >
            <On Platform="Android" Value="sans-serif-medium"/>
            <On Platform="iOS" Value="Arial"/>
</OnPlatform>

While this does not work and gives the error mentioned before.

<OnPlatform x:Key="RegularFontFamily"
                    x:TypeArguments="x:String"
                    >
    <On Platform="Android" Value="{StaticResource AppFontFamily}"/>
    <On Platform="iOS" Value="{StaticResource AppFontFamily}"/>
</OnPlatform>

Another side note that might be related is that when using a merged resource dictionary another error appears when using namely:
Error: Collection was modified; enumeration operation may not execute. XamlC

So in my App.xaml file I have

<ResourceDictionary.MergedDictionaries>
    <local:MyAppTheme />
</ResourceDictionary.MergedDictionaries>

and in a separate file MyAppTheme

<ResourceDictionary>
    <OnPlatform x:Key="ImageHighlightedColor" x:TypeArguments="Color" Default="{ StaticResource AccentColor }" />
</ResourceDictionary>

Im Running on a Mac and compiling for iOS

@samhouts
Copy link
Member

I was not able to reproduce this with the given project. It builds and runs with RC1. Is there more required?

@samhouts samhouts added the s/needs-info Issue needs more info from the author label Sep 19, 2023
@ghost
Copy link

ghost commented Sep 19, 2023

Hi @brunck. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@brunck
Copy link
Contributor Author

brunck commented Sep 19, 2023

@samhouts It definitely does not build for me using the latest VS 2022 preview. Just open and try to build the solution in the MauiResourceDictionaryBuildError folder. No other action is required.
What other info do you need from me?

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Sep 19, 2023
@XamlTest XamlTest added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Sep 21, 2023
@XamlTest
Copy link
Collaborator

Verified this on Visual Studio Enterprise 17.8.0 Preview 2.0(8.0.0-rc.1.9171). Repro with the given project:
MauiRc1App.zip

image

@StephaneDelcroix
Copy link
Contributor

the Collection was modified error is fixed. this might be related to OnPlatform optimisation, checking if I can repro and unit test

@StephaneDelcroix
Copy link
Contributor

I can not reproduce this. which platform are you compiling for ?

@brunck
Copy link
Contributor Author

brunck commented Sep 22, 2023

This is single-project MAUI…how do you compile for just one platform? Android I guess?

@samhouts
Copy link
Member

Oh, that's strange. If I hit F5, it builds and runs successfully. If I just do Build, it fails.

Confirmed that this regressed between 8.0.0-preview.7.8842 and 8.0.0-rc.1.9171. #5611 looks sus, @StephaneDelcroix

@samhouts samhouts added i/regression This issue described a confirmed regression on a currently supported version and removed s/needs-attention Issue has more information and needs another look potential-regression This issue described a possible regression on a currently supported version., verification pending labels Sep 28, 2023
@brunck
Copy link
Contributor Author

brunck commented Sep 28, 2023

That’s very strange! I don’t think I’ve ever seen or heard of this type of thing happening before.

@StephaneDelcroix
Copy link
Contributor

trying again to produce a unit test...

@StephaneDelcroix
Copy link
Contributor

StephaneDelcroix commented Sep 29, 2023

I think I understand what's going on. SimplifyOnPlatform was meant to simplify code generation, but using it as a Resource was never a use case. I might need to rethink this. Depending on the deadlines, we might have to revert #5611. @samhouts your call

StephaneDelcroix added a commit that referenced this issue Sep 29, 2023
As reported in #17461, OnPlatform simplification cause some issues
- while used as a Resource (#17461, unable to unit test for now)
- doesn't type convert. On nodes shouldn't be replaced by the Value, but
  an element node (<On Platform="..." Value="Red" /> should generate
<Color x:Key="foo">Red</Color>. right now it only generated "Red"

- fixes #17461
StephaneDelcroix added a commit that referenced this issue Sep 29, 2023
As reported in #17461, OnPlatform simplification cause some issues
- while used as a Resource (#17461, unable to unit test for now)
- doesn't type convert. On nodes shouldn't be replaced by the Value, but
  an element node (<On Platform="..." Value="Red" /> should generate
<Color x:Key="foo">Red</Color>. right now it only generated "Red"

- fixes #17461
StephaneDelcroix added a commit that referenced this issue Oct 17, 2023
As reported in #17461, OnPlatform simplification cause some issues
- while used as a Resource (#17461, unable to unit test for now)
- doesn't type convert. On nodes shouldn't be replaced by the Value, but
  an element node (<On Platform="..." Value="Red" /> should generate
<Color x:Key="foo">Red</Color>. right now it only generated "Red"

- fixes #17461
StephaneDelcroix added a commit that referenced this issue Oct 17, 2023
As reported in #17461, OnPlatform simplification cause some issues
- while used as a Resource (#17461, unable to unit test for now)
- doesn't type convert. On nodes shouldn't be replaced by the Value, but
  an element node (<On Platform="..." Value="Red" /> should generate
<Color x:Key="foo">Red</Color>. right now it only generated "Red"

- fixes #17461
github-actions bot pushed a commit that referenced this issue Oct 19, 2023
As reported in #17461, OnPlatform simplification cause some issues
- while used as a Resource (#17461, unable to unit test for now)
- doesn't type convert. On nodes shouldn't be replaced by the Value, but
  an element node (<On Platform="..." Value="Red" /> should generate
<Color x:Key="foo">Red</Color>. right now it only generated "Red"

- fixes #17461
samhouts pushed a commit that referenced this issue Oct 20, 2023
As reported in #17461, OnPlatform simplification cause some issues
- while used as a Resource (#17461, unable to unit test for now)
- doesn't type convert. On nodes shouldn't be replaced by the Value, but
  an element node (<On Platform="..." Value="Red" /> should generate
<Color x:Key="foo">Red</Color>. right now it only generated "Red"

- fixes #17461
github-actions bot pushed a commit that referenced this issue Oct 23, 2023
As reported in #17461, OnPlatform simplification cause some issues
- while used as a Resource (#17461, unable to unit test for now)
- doesn't type convert. On nodes shouldn't be replaced by the Value, but
  an element node (<On Platform="..." Value="Red" /> should generate
<Color x:Key="foo">Red</Color>. right now it only generated "Red"

- fixes #17461
rmarinho pushed a commit that referenced this issue Oct 23, 2023
* [X] revert #5611

As reported in #17461, OnPlatform simplification cause some issues
- while used as a Resource (#17461, unable to unit test for now)
- doesn't type convert. On nodes shouldn't be replaced by the Value, but
  an element node (<On Platform="..." Value="Red" /> should generate
<Color x:Key="foo">Red</Color>. right now it only generated "Red"

- fixes #17461

* disable failing test

---------

Co-authored-by: Stephane Delcroix <stephane@delcroix.org>
@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2023
@samhouts samhouts added the fixed-in-8.0.0-rc.2.9511 Look for this fix in 8.0.0-rc.2.9511 label Jan 31, 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.0-rc.2.9511 Look for this fix in 8.0.0-rc.2.9511 i/regression This issue described a confirmed regression on a currently supported version s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants