Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 26, 2025

GitHub Issue: closes #21935

PR Type:

🐞 Bugfix

What is the current behavior? 🤔

Using invalid values like Margin="auto,0,0,0" in XAML generates CS0103: The name 'auto' does not exist in the current context in generated code. The error points to the generated C# file instead of the XAML source, making it difficult for developers to understand and fix the issue. Additionally, the invalid generated code prevents successful compilation.

What is the new behavior? 🚀

The XAML generator now validates property values and produces proper UXAML0001 diagnostics pointing to the correct location in the XAML file when an invalid value is detected. Instead of throwing exceptions that cause invalid C# generation, the generator uses AddError() to report errors while generating valid default values, allowing compilation to continue and all XAML errors to be shown at once.

Validated property types:

  • Thickness (Margin, Padding, etc.): Validates each component is a valid number, generates new Thickness(0) on error
  • CornerRadius: Validates each component is a valid number, generates new CornerRadius(0) on error
  • GridLength (RowDefinition.Height, ColumnDefinition.Width): Validates the value can be parsed, generates new GridLength(0f, Pixel) on error
  • Double/Single: Validates the value is a valid number, generates 0d or 0f on error
  • Vector2, Vector3, Point, Size, Matrix: Validates each component is a valid number via SplitAndJoin, generates "0, 0" on error

Example:

<Grid Margin="auto,0,0,0">
</Grid>

Now produces: UXAML0001: Invalid Thickness value 'auto,0,0,0'. Each component must be a valid number while generating new Thickness(0) to ensure valid C# code.

Changes:

  • Added validation in XamlFileGenerator.BuildThickness() for Thickness values (changed to non-static to access AddError)
  • Added validation in XamlFileGenerator.BuildCornerRadius() for CornerRadius values (changed to non-static to access AddError)
  • Added validation in XamlFileGenerator.BuildGridLength() for GridLength values (changed to non-static to access AddError)
  • Added validation in XamlFileGenerator.GetFloatingPointLiteral() for Double/Single values
  • Added validation in XamlFileGenerator.SplitAndJoin() for Vector2, Vector3, Point, Size, Matrix types
  • Replaced all throw new XamlGenerationException() with AddError() calls to allow continued code generation with default values
  • Added tests: When_Invalid_Margin_Value, When_Invalid_CornerRadius_Value, When_Invalid_GridLength_Value, When_Invalid_Double_Value, When_Invalid_Point_Value

PR Checklist ✅

Please check if your PR fulfills the following requirements:

Other information ℹ️

  • Tests added to Given_Parser.cs in Uno.UI.SourceGenerators.Tests, positioned right after the When_Invalid_Object_Property test for logical grouping of invalid XAML value tests.
  • The validation uses double.TryParse() to check component values before generating code.
  • For GridLength and floating point types, validation is only performed when an owner (XamlMemberDefinition) is available to ensure backward compatibility with internal calls.
  • Integer types (Int32, Int64, Int16, Byte) are intentionally not validated as they have special parsing behavior (e.g., Int32 ignores content after spaces).
  • Error reporting uses AddError() instead of throwing exceptions to ensure valid C# code is always generated, preventing CS0103 compilation errors while still reporting UXAML0001 diagnostics at the correct XAML locations.
Original prompt

This section details on the original issue you should resolve

<issue_title>[xaml-gen] CS0103 with invalid XAML</issue_title>
<issue_description>### What would you like to be added? 💡

When adding Margin="auto,0,0,0" we get error CS0103: The name 'auto' does not exist in the current context in gen'ed code. We should get a XAML0001 at the right location in the XAML

Why is this needed? 🤔

To improve dev experience

Renderer 🎨

  • Skia
  • Native

For which platforms 📱💻🖥️

No response

Anything else we need to know? 💬

No response</issue_description>

<agent_instructions>On the model of test When_Invalid_Object_Property, create test in file https://github.com/unoplatform/uno/blob/master/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Given_Parser.cs that repro this failure when Margin="auto,0,0,0"</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@carldebilly @dr1rrb I saw it this morning on my side, so that's definitely something the model likes to generate. What do you think should be the right fix for that? What should be the correct correction to it? Because the actual _intention_ is unclear, nor the right fix.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@CLAassistant
Copy link

CLAassistant commented Nov 26, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ dr1rrb
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI changed the title [WIP] Add test for invalid XAML margin property test: Add test to reproduce CS0103 error with invalid Margin value Nov 26, 2025
Copilot AI requested a review from dr1rrb November 26, 2025 18:24
@unodevops
Copy link
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21976/wasm-skia-net9/index.html

@dr1rrb
Copy link
Member

dr1rrb commented Nov 26, 2025

@copilot Please move it to line 309, right after the When_Invalid_Object_Property test

Copy link
Contributor Author

Copilot AI commented Nov 26, 2025

@copilot Please move it to line 309, right after the When_Invalid_Object_Property test

Done in d88ccac - moved the test to line 310, right after When_Invalid_Object_Property.

@dr1rrb
Copy link
Member

dr1rrb commented Nov 26, 2025

@copilot src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Given_Parser.cs:335

This should be DiagnosticResult.CompilerError("UXAML0001"), please adjust the test and make adjustemnts in the XAMLFileGenerator to support this case

Copy link
Contributor Author

Copilot AI commented Nov 26, 2025

@copilot src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Given_Parser.cs:335

This should be DiagnosticResult.CompilerError("UXAML0001"), please adjust the test and make ad...

Done in 4c7c4df - Updated the test to expect UXAML0001 and added validation in XamlFileGenerator.BuildThickness() to check that each Thickness component is a valid number. The method now throws a XamlGenerationException with a descriptive message when an invalid value like auto is used.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 7tjvsblobprodcus341.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • m8dvsblobprodcus37.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • pdfvsblobprodcus380.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • u3hvsblobprodcus371.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title test: Add test to reproduce CS0103 error with invalid Margin value fix: Generate UXAML0001 error for invalid Thickness values instead of CS0103 Nov 26, 2025
@dr1rrb
Copy link
Member

dr1rrb commented Nov 26, 2025

@copilot Good 👍

Please do the same for:

  • CornerRadius: src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs:5334
  • GridLength: src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs:5167
  • All numerics type: src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs:4996

Add tests for all of those cases

Copy link
Contributor Author

Copilot AI commented Nov 26, 2025

@copilot Good 👍

Please do the same for:...

Done in 70e2cef - Added validation for:

  • CornerRadius: BuildCornerRadius() now validates each component
  • GridLength: BuildGridLength() now catches parsing errors
  • Numeric types: Added validation for Int32, Int64, Int16, Byte in switch cases, and Double/Single in GetFloatingPointLiteral()

Added tests:

  • When_Invalid_CornerRadius_Value
  • When_Invalid_GridLength_Value
  • When_Invalid_Double_Value
  • When_Invalid_Int32_Value

Copilot AI changed the title fix: Generate UXAML0001 error for invalid Thickness values instead of CS0103 fix: Generate UXAML0001 error for invalid property values instead of CS0103 Nov 26, 2025
@dr1rrb
Copy link
Member

dr1rrb commented Nov 26, 2025

@copilot src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs:4803-4822

Non, défait ça, le commenatire dit clairement que y'a un cas particulier pour Int32, remet return IgnoreStartingFromFirstSpaceIgnoreLeading(GetMemberValue());

Par contre tu n'a pas changé le SplitAndJoin qui est utilisé par System.Numerics.Vector2 et System.Numerics.Vector3, Windows.Foundation.Point etc. Je veux m'assurer que les valeurs soient correctes!

…or2, Vector3, Point, Size, Matrix types

Co-authored-by: dr1rrb <[email protected]>
Copy link
Contributor Author

Copilot AI commented Nov 26, 2025

@copilot src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs:4803-4822

Non, défait ça, le commenatire dit clairement que y'a un cas particulier pour Int32, remet `return...

Done in 3c8b545:

  • Reverted Int32/Int64/Int16/Byte validation back to original behavior
  • Added validation to SplitAndJoin function which now validates each numeric component for Vector2, Vector3, Point, Size, and Matrix types
  • Replaced When_Invalid_Int32_Value test with When_Invalid_Point_Value test

@unodevops
Copy link
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21976/wasm-skia-net9/index.html

@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21976/docs/index.html

@nventive-devops
Copy link
Contributor

The build 185294 found UI Test snapshots differences: android-28-net9: 18, android-28-net9-Snap: 35, ios: 4, ios-Snap: 64, skia-linux-screenshots: 69, skia-windows-screenshots: 457, wasm: 114, wasm-automated-net10.0-WinUI-Benchmarks-automated: 0, wasm-automated-net10.0-WinUI-Default-automated: 15, wasm-automated-net10.0-WinUI-RuntimeTests-0: 0, wasm-automated-net10.0-WinUI-RuntimeTests-1: 0, wasm-automated-net10.0-WinUI-RuntimeTests-2: 0

Details
  • android-28-net9: 18 changed over 825

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Detereminate_ProgressRing_Validation25_[#FF0000_#008000_#FF0000_#FF0000]_Progress-Ring-Value-25
    • Detereminate_ProgressRing_Validation75_[#FF0000_#008000_#008000_#008000]_Progress-Ring-Value-75
    • Detereminate_ProgressRing_Validation50_[#FF0000_#008000_#008000_#FF0000]_Progress-Ring-Value-50
    • ListView_SelectedItems_SamplesApp_Windows_UI_Xaml_Controls_ListView_ListViewSelectedItems
    • ListView_ListViewWithHeader_InitializesTest_SamplesApp_Windows_UI_Xaml_Controls_ListView_HorizontalListViewGrouped
    • SequentialAnimations_SamplesApp_Windows_UI_Xaml_Media_Animation_SequentialAnimationsPage
    • ProgressRing_IsEnabled_Running_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
    • ProgressRing_Visibility_Collapsed_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
    • UpDownEnabledTest_UITests_Shared_Microsoft_UI_Xaml_Controls_NumberBoxTests_NumberBoxPage
    • WebView_NavigateToAnchor_Initial
    • When_MultipleSelectionWithoutItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_NoSelection_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_SingleSelectionWithoutItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_Parent_PointerMoved_After_drag_on_non-scrolling_ScrollViewer
    • When_Parent_PointerMoved_After_drag_on_ScrollViewer_-_touch
    • When_ExtendedSelectionWithoutItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • DecimalFormatterTest_UITests_Shared_Microsoft_UI_Xaml_Controls_NumberBoxTests_NumberBoxPage
    • NativeCommandBar_Size_Uno_UI_Samples_Content_UITests_CommandBar_CommandBar_Dynamic
  • android-28-net9-Snap: 35 changed over 1077

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Image_Uno_UI_Samples_UITests_Image_Image_Stretch_Alignment_Smaller_Uno_UI_Samples_UITests_Image_Image_Stretch_Alignment_Smaller
    • NavigationView_MUXControlsTestApp_NavigationViewRS4Page_MUXControlsTestApp_NavigationViewRS4Page
    • Default_Uno_UI_Samples_Content_UITests_WebView_WebView_AnchorNavigation_Uno_UI_Samples_Content_UITests_WebView_WebView_AnchorNavigation
    • Gesture_Recognizer_Pointer_Events_test_bench_UITests_Shared_Windows_UI_Input_GestureRecognizer_PointersEvents
    • Scrolling_MUXControlsTestApp_ScrollViewDynamicPage_MUXControlsTestApp_ScrollViewDynamicPage
    • TextBlock_UITests_Shared_Windows_UI_Xaml_Controls_TextBlockControl_TextBlock_Layout_UITests_Shared_Windows_UI_Xaml_Controls_TextBlockControl_TextBlock_Layout
    • NavigationView_MUXControlsTestApp_NavigationViewTopNavOnlyPage_MUXControlsTestApp_NavigationViewTopNavOnlyPage
    • NavigationView_MUXControlsTestApp_NavigationViewTopNavPage_MUXControlsTestApp_NavigationViewTopNavPage
    • RatingControl_UITests_Microsoft_UI_Xaml_Controls_RatingControlTests_RatingControlPage_UITests_Microsoft_UI_Xaml_Controls_RatingControlTests_RatingControlPage
    • Brushes_Uno_UI_Samples_UITests_ImageBrushTestControl_Ellipse_Uno_UI_Samples_UITests_ImageBrushTestControl_Ellipse
    • Image_UITests_Windows_UI_Xaml_Controls_ImageTests_SvgImageSource_Basic_UITests_Windows_UI_Xaml_Controls_ImageTests_SvgImageSource_Basic
    • MUX_UITests_Shared_Microsoft_UI_Xaml_Controls_TreeViewTests_TreeViewPage_UITests_Shared_Microsoft_UI_Xaml_Controls_TreeViewTests_TreeViewPage
    • Pickers_UITests_Windows_UI_Xaml_Controls_CalendarView_CalendarView_Theming_UITests_Windows_UI_Xaml_Controls_CalendarView_CalendarView_Theming
    • ListView_ListViewResizable_SamplesApp_Windows_UI_Xaml_Controls_ListView_ListViewResizable
    • TabView_MUXControlsTestApp_TabViewPage_MUXControlsTestApp_TabViewPage
    • CommandBar_Examples_Uno_UI_Samples_Content_UITests_CommandBar_CommandBar_Examples
    • TeachingTip_UITests_Microsoft_UI_Xaml_Controls_TeachingTipTests_TeachingTipPage_UITests_Microsoft_UI_Xaml_Controls_TeachingTipTests_TeachingTipPage
    • Icons_UITests_Microsoft_UI_Xaml_Controls_ImageIconTests_ImageIconPage_UITests_Microsoft_UI_Xaml_Controls_ImageIconTests_ImageIconPage
    • Icons_UITests_Shared_Windows_UI_Xaml_Controls_BitmapIconTests_BitmapIcon_Foreground_UITests_Shared_Windows_UI_Xaml_Controls_BitmapIconTests_BitmapIcon_Foreground
    • CommandBarFlyout_MUXControlsTestApp_CommandBarFlyoutPage_MUXControlsTestApp_CommandBarFlyoutPage
  • ios: 4 changed over 255

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ProgressRing_IsEnabled_Running_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
    • Check_ListView_Swallows_Measure_UITests_Shared_Windows_UI_Xaml_Controls_ListView_ListView_With_ListViews_Count_Measure
    • ProgressRing_Visibility_Collapsed_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
    • TextBox_UpdatedBinding_On_OneWay_Mode_UITests_Windows_UI_Xaml_Controls_TextBox_TextBox_Bindings
  • ios-Snap: 64 changed over 994

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Icons_UITests_Shared_Windows_UI_Xaml_Controls_BitmapIconTests_BitmapIcon_Foreground_UITests_Shared_Windows_UI_Xaml_Controls_BitmapIconTests_BitmapIcon_Foreground
    • Microsoft_UI_Xaml_Media_UITests_Windows_UI_Xaml_Media_ThemeShadowTests_ThemeShadow_Overlap_UITests_Windows_UI_Xaml_Media_ThemeShadowTests_ThemeShadow_Overlap
    • Popup_MessageDialog_UITests_Shared_Windows_UI_Xaml_Controls_Popup_MessageDialog
    • Brushes_EllipsemaskingEllipseGrid_Uno_UI_Samples_UITests_ImageBrushTestControl_EllipsemaskingEllipseGrid
    • Brushes_PathImageBrushfill_Uno_UI_Samples_UITests_ImageBrushTestControl_PathImageBrushfill
    • Buttons_Custom_Button_With_ContentTemplate_Uno_UI_Samples_Content_UITests_ButtonTestsControl_Custom_Button_With_ContentTemplate
    • Brushes_PanelImageBrush_Uno_UI_Samples_UITests_ImageBrushTestControl_PanelImageBrush
    • Grid_CenteredGridinGridwiththreefixedsizechildren_Uno_UI_Samples_Content_UITests_GridTestsControl_CenteredGridinGridwiththreefixedsizechildren
    • Image_Image_Stretch_None_Uno_UI_Samples_UITests_ImageTestsControl_Image_Stretch_None
    • Microsoft_UI_Composition_UITests_Windows_UI_Composition_MixTransformCliPropertyAndClippedByParentWithBorders_Then_RenderingIsValid_UITests_Windows_UI_Composition_MixTransformCliPropertyAndClippedByParentWithBorders_Then_RenderingIsValid
    • Image_UITests_Shared_Windows_UI_Xaml_Controls_ImageTests_Image_Stretch_Algmnt_Inf_Horizontal_UITests_Shared_Windows_UI_Xaml_Controls_ImageTests_Image_Stretch_Algmnt_Inf_Horizontal
    • Microsoft_UI_Composition_UITests_Windows_UI_Composition_TransformElementClippedByParent_Then_ClippingAppliedPostRendering_UITests_Windows_UI_Composition_TransformElementClippedByParent_Then_ClippingAppliedPostRendering
    • Image_UITests_Shared_Windows_UI_Xaml_Controls_ImageTests_Image_Stretch_Algmnt_Inf_Vertical_UITests_Shared_Windows_UI_Xaml_Controls_ImageTests_Image_Stretch_Algmnt_Inf_Vertical
    • Image_UITests_Shared_Windows_UI_Xaml_Controls_ImageTests_Image_Stretch_Alignment_SizeOnControl_UITests_Shared_Windows_UI_Xaml_Controls_ImageTests_Image_Stretch_Alignment_SizeOnControl
    • NavigationView_MUXControlsTestApp_NavigationViewMenuItemStretchPage_MUXControlsTestApp_NavigationViewMenuItemStretchPage
    • NavigationView_MUXControlsTestApp_NavigationViewSelectedItemEdgeCasePage_MUXControlsTestApp_NavigationViewSelectedItemEdgeCasePage
    • NavigationView_MUXControlsTestApp_NavigationViewAnimationPage_MUXControlsTestApp_NavigationViewAnimationPage
    • NavigationView_MUXControlsTestApp_NavigationViewStretchPage_MUXControlsTestApp_NavigationViewStretchPage
    • NavigationView_MUXControlsTestApp_NavigationViewRS3Page_MUXControlsTestApp_NavigationViewRS3Page
    • NavigationView_MUXControlsTestApp_NavigationViewBlankPage1_MUXControlsTestApp_NavigationViewBlankPage1
  • skia-linux-screenshots: 69 changed over 2306

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • Buttons.png-dark
    • Buttons.png
    • Examples.png-dark
    • Examples.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_Enumeration.png-dark
    • Gamepad_Enumeration.png
    • ImageSourceUrlMsAppDataScheme.png-dark
    • ImageSourceUrlMsAppDataScheme.png
    • Image_Margin_Large.png-dark
    • Image_Margin_Large.png
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • DisplayInformation.png-dark
    • DisplayInformation.png
    • ImageIconPage.png-dark
    • ImageIconPage.png
  • skia-windows-screenshots: 457 changed over 2306

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AppBarButtonTest.png
    • AppBarToggleButtonTest.png
    • Attributed_text_FontSize_Changing.png
    • AutoSizedPathCentered.png-dark
    • AutoSizedPathCentered.png
    • Basics.png
    • Basics_Automated.png-dark
    • Border_With_CompositeTransform.png-dark
    • FixedWidth.png-dark
    • FixedWidth.png
    • Grid_Multi_Column_Span.png-dark
    • Grid_Multi_Column_Span.png
    • Arrange_Performance01.png
    • Basics Pivot Test.png-dark
    • Basics Pivot Test.png
    • Border_With_CompositeTransform.png
    • Border_With_Off_Centre_RotateTransform.png-dark
    • CheckBox_Button_UWA_Style.png-dark
    • CheckBox_Button_UWA_Style.png
    • ComboBox_SelectedIndex.png-dark
  • wasm: 114 changed over 1058

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListView_Inside_ListView
    • UITests.Microsoft_UI_Xaml_Controls.TeachingTipTests.TeachingTipBasicPage
    • UITests.Windows_UI_Xaml_Controls.TextBox.TextBox_WithPadding_Focus
    • UITests.Windows_UI_Xaml_Controls.TextBox.TextBox_Wrapping
    • UITests.Windows_UI_Xaml_Media_Animation.ColorAnimation_Background
    • UITests.Windows_UI_Xaml_Media_Animation.ColorAnimation_Fill
    • UITests.Windows_UI_Xaml_Media_Animation.DoubleAnimation_FinalState_Transforms
    • initial_state
    • Uno.UI.Samples.Content.UITests.ButtonTestsControl.Button_Enabled_Control_Disabled
    • SamplesApp.Samples.Windows_UI_Xaml_Controls.NavigationViewTests.NavigationView_BasicNavigation
    • SamplesApp.Wasm.Windows_UI_Xaml_Controls.ComboBox.ComboBox_PlaceholderText
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListView_Expandable_Item
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListView_Expandable_Item_Large
    • UITests.Microsoft_UI_Xaml_Controls.NumberBoxTests.NumberBox_Header
    • UITests.Microsoft_UI_Xaml_Controls.TabViewTests.TabViewBasicPage
    • UITests.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_NavigationProperties
    • UITests.Microsoft_UI_Xaml_Controls.TabViewTests.TabViewItemsSourceTests
    • UITests.Windows_ApplicationModel.DataTransfer.DataTransferManagerTests
    • UITests.Windows_Devices.Midi.MidiDeviceInput
    • UITests.Windows_UI_Xaml.xLoadTests.xLoad_xBind
  • wasm-automated-net10.0-WinUI-Benchmarks-automated: 0 changed over 1

  • wasm-automated-net10.0-WinUI-Default-automated: 15 changed over 877

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • SequentialAnimations_SamplesApp_Windows_UI_Xaml_Media_Animation_SequentialAnimationsPage
    • When_NoSelectionWithItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_MultipleSelectionWithoutItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_NoSelection_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_StretchAndAlignmentNone_ImageBrush-50-50-None-XLeft-YBottom
    • Default_StrokeThickness_MyEllipse
    • Default_StrokeThickness_MyRect
    • Default_StrokeThickness_MyPolyline
    • ListView_SelectedItems_SamplesApp_Windows_UI_Xaml_Controls_ListView_ListViewSelectedItems
    • TestProgressRing_InitialState_UITests_Microsoft_UI_Xaml_Controls_ProgressRing_WinUIProgressRing_Features
    • Default_StrokeThickness_MyPath
    • Default_StrokeThickness_MyLine
    • When_Theme_Changed_No_Crash_UITests_Windows_UI_Xaml_Controls_CalendarView_CalendarView_Theming
    • Default_StrokeThickness_MyPolygon
    • When_SingleSelectionWithoutItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
  • wasm-automated-net10.0-WinUI-RuntimeTests-0: 0 changed over 1

  • wasm-automated-net10.0-WinUI-RuntimeTests-1: 0 changed over 1

  • wasm-automated-net10.0-WinUI-RuntimeTests-2: 0 changed over 1

@unodevops
Copy link
Contributor

⚠️⚠️ The build 185294 has failed on Uno.UI - CI.

@dr1rrb
Copy link
Member

dr1rrb commented Dec 8, 2025

@copilot The throw cause invalid CS to be generated. Please replace the throw you added by AddError and instead return default value.

Copy link
Contributor Author

Copilot AI commented Dec 8, 2025

@copilot The throw cause invalid CS to be generated. Please replace the throw you added by AddError and instead return default value.

Done in cdec53b - Replaced all throw new XamlGenerationException() with AddError() calls and return appropriate default values:

  • Thickness: returns new Thickness(0)
  • CornerRadius: returns new CornerRadius(0)
  • GridLength: returns new GridLength(0f, Pixel)
  • Double/Single: returns 0d or 0f
  • SplitAndJoin (Vector2, Point, etc.): returns "0, 0"

Also made BuildThickness, BuildCornerRadius, and BuildGridLength non-static to access the instance method AddError().

Copilot AI changed the title fix: Generate UXAML0001 error for invalid property values instead of CS0103 fix: Generate UXAML0001 error for invalid property values with valid C# fallback Dec 8, 2025
@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21976/docs/index.html

@github-actions github-actions bot added the area/code-generation Categorizes an issue or PR as relevant to code generation label Dec 8, 2025
@dr1rrb dr1rrb marked this pull request as ready for review December 8, 2025 22:53
Copilot AI review requested due to automatic review settings December 8, 2025 22:53
Copilot AI requested a review from dr1rrb December 8, 2025 22:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the developer experience when using invalid XAML property values by generating proper UXAML0001 diagnostics at the correct XAML source location instead of CS0103 errors in generated C# code. The fix addresses the original issue where Margin="auto,0,0,0" would generate confusing C# compilation errors pointing to generated files rather than the XAML source.

Key changes:

  • Added validation for numeric property values (Thickness, CornerRadius, GridLength, Double/Single, Vector2, Vector3, Point, Size, Matrix)
  • Changed methods from static to instance to enable access to AddError() for proper error reporting
  • Generates valid default values (e.g., new Thickness(0)) when validation fails, allowing compilation to continue and showing all errors at once

Reviewed changes

Copilot reviewed 2 out of 17 changed files in this pull request and generated 2 comments.

File Description
XamlFileGenerator.cs Added validation logic to BuildThickness, BuildCornerRadius, BuildGridLength, GetFloatingPointLiteral, and SplitAndJoin methods; changed method signatures from static to instance to access AddError(); validates numeric components using double.TryParse with InvariantCulture
Given_Parser.cs Added 5 new tests covering invalid values for Margin (Thickness), CornerRadius, GridLength (Height), Width (Double/Single), and RenderTransformOrigin (Point)
Out/Given_Parser/WhIn*/XamlCodeGenerator_*.cs Generated test output files showing proper UXAML0001 diagnostics and valid fallback C# code with default values

@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21976/docs/index.html

@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21976/docs/index.html

@dr1rrb
Copy link
Member

dr1rrb commented Dec 10, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/code-generation Categorizes an issue or PR as relevant to code generation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[xaml-gen] CS0103 with invalid XAML

5 participants