Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 10, 2025

  • Explore the repository and understand XamlReader implementation
  • Identify the bug in markup extension parsing (IsMarkupExtension only checks hardcoded list)
  • Create unit tests to reproduce the issue with custom markup extensions
  • Fix IsMarkupExtension to properly detect custom markup extensions
  • Fix ProcessMemberMarkupExtension to handle custom markup extensions
  • Fix code formatting issues
  • Address code review feedback
  • Add better error handling with line/column information
  • Fix collection property handling for inline markup extensions
  • Document the changes
  • Validate the fix with unit tests (awaiting CI)
  • Run existing test suite to ensure no regressions (awaiting CI)

Summary

Fixed an issue where XamlReader.Load would throw NotSupportedException when encountering custom markup extensions (e.g., {utu:Responsive Narrow=1, Wide=2}).

Changes

  1. Modified IsMarkupExtension to detect any type inheriting from MarkupExtension using new IsCustomMarkupExtension helper
  2. Added ProcessCustomMarkupExtension to handle custom markup extension evaluation with proper error handling and collection property support
  3. Added unit tests to verify custom markup extensions work correctly

Latest Fix

Fixed test failure in When_MarkupExtension_ServiceProvider_InlineLiteral by adding support for collection properties (like Panel.Children). The method now:

  • Checks if the target property is an initialized collection using TypeResolver.IsInitializedCollection
  • Gets the collection instance via the property getter
  • Adds the markup extension result to the collection using the Add method
  • Falls back to normal property setter for non-collection properties

Closes https://github.com/unoplatform/uno/issues/XXXXX

Original prompt

This section details on the original issue you should resolve

<issue_title>XamlReader.Load exception - unable to parse markup extension</issue_title>
<issue_description>### Current behavior 🐛

Attempting to call XamlReader.Load on XAML that contains uses a custom markup extension fail to parse

var xaml =
    """
    <Grid Grid.RowSpan="{utu:Responsive Narrow=1, Wide=2}" xmlns:utu="using:Uno.Toolkit.UI" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" />
    """;

var element = XamlReader.Load(xaml) as UIElement;
Image

Sample App
ParsingSample.zip

Expected behavior 🎯

No parsing errors - markup extension should be correctly parsed and loaded

How to reproduce it (as minimally and precisely as possible) 🔬

No response

Workaround 🛠️

No response

Renderer 🎨

  • Skia
  • Native

Affected platforms 📱💻🖥️

No response

Uno.Sdk version (and other relevant versions) 📦

Uno.Sdk 6.4.40

IDE version 🧑‍💻

Visual Studio 2026 18.0.2

Anything else we need to know? 💬

Call Stack:

 	 	[Uno.Xaml.XamlParseException user-unhandled]	
 	Uno.UI.dll!Microsoft.UI.Xaml.Markup.Reader.XamlObjectBuilder.Build(object component, bool createInstanceFromXClass)	Unknown
 	Uno.UI.dll!Microsoft.UI.Xaml.Markup.XamlReader.Load(string xaml)	Unknown
>	ParsingSampleApp.dll!ParsingSampleApp.MainPage.RunMarkupClicked(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) Line 33	C#
 	ParsingSampleApp.dll!ParsingSampleApp.MainPage.__MainPage_3d1508bf9a2ba168f5d35e6e084167f9.__PagΞ0_ScrVieΞ0_GriΞ0_StaPanΞ2_But_Cli_Click_Handler.Invoke(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) Line 226	C#
 	Uno.UI.dll!Microsoft.UI.Xaml.Controls.Primitives.ButtonBase.OnClick()	Unknown
 	Uno.UI.dll!Microsoft.UI.Xaml.Controls.Button.OnClick()	Unknown
 	Uno.UI.dll!Microsoft.UI.Xaml.Controls.Primitives.ButtonBase.PerformPointerUpAction()	Unknown
 	Uno.UI.dll!Microsoft.UI.Xaml.Controls.Primitives.ButtonBase.OnPointerReleased(Microsoft.UI.Xaml.Input.PointerRoutedEventArgs args)	Unknown
 	Uno.UI.dll!Microsoft.UI.Xaml.Controls.Control..cctor.AnonymousMethod__389_10(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs args)	Unknown
 	Uno.UI.dll!Microsoft.UI.Xaml.UIElement.InvokeHandler(object handler, Microsoft.UI.Xaml.RoutedEventArgs args)	Unknown
 	Uno.UI.dll!Microsoft.UI.Xaml.UIElement.InvokeHandlers(System.Collections.Generic.IList<Microsoft.UI.Xaml.UIElement.RoutedEventHandlerInfo> handlers, Microsoft.UI.Xaml.RoutedEventArgs args, ref bool isHandled)	Unknown
 	Uno.UI.dll!Microsoft.UI.Xaml.UIElement.RaiseEvent(Microsoft.UI.Xaml.RoutedEvent routedEvent, Microsoft.UI.Xaml.RoutedEventArgs args, Microsoft.UI.Xaml.UIElement.BubblingContext ctx)	Unknown
 	Uno.UI.dll!Microsoft.UI.Xaml.UIElement.RaisePointerEvent.__InnerRaiseEvent|662_0(Microsoft.UI.Xaml.RoutedEvent evt, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs args, Microsoft.UI.Xaml.UIElement.BubblingContext ctx, ref (Microsoft.UI.Xaml.UIElement sender, Microsoft.UI.Xaml.RoutedEvent event, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs args) pendingRaisedEvent)	Unknown
 	Uno.UI.dll!Microsoft.UI.Xaml.UIElement.RaisePointerEvent(Microsoft.UI.Xaml.RoutedEvent evt, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs args, Microsoft.UI.Xaml.UIElement.BubblingContext ctx)	Unknown
 	Uno.UI.dll!Microsoft.UI.Xaml.UIElement.SetPressed(Microsoft.UI.Xaml.Input.PointerRoutedEventArgs args, bool isPressed, Microsoft.UI.Xaml.UIElement.BubblingContext ctx)	Unknown
 	Uno.UI.dll!Microsoft.UI.Xaml.UIElement.OnPointerUp(Microsoft.UI.Xaml.Input.PointerRoutedEventArgs args, Microsoft.UI.Xaml.UIElement.BubblingContext ctx)	Unknown
 	Uno.UI.dll!Uno.UI.Xaml.Core.InputManager.PointerManager..cctor.AnonymousMethod__88_5(Microsoft.UI.Xaml.UIElement elt, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs args, Microsoft.UI.Xaml.UIElement.BubblingContext ctx)	Unknown
 	Uno.UI.dll!Uno.UI.Xaml.Core.InputManager.PointerManager.RaiseUsingCaptures(Uno.UI.Xaml.Core.InputManager.PointerManager.PointerEvent evt, Microsoft.UI.Xaml.UIElement originalSource, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs routedArgs, bool setCursor)	Unknown
 	Uno.UI.dll!Uno.UI.Xaml.Core.InputManager.PointerManager.OnPointerReleased(Windows.UI.Core.PointerEventArgs args, bool isInjected)	Unknown
 	Uno.UI.dll!Uno.UI.Xaml.Core.InputManager.PointerManager.Init.AnonymousMethod__17_4(object c, Windows.UI.Core.PointerEventArgs e)	Unknown
 	Uno.UI.Runtime.Skia.Win32.dll!Uno.UI.Runtime.Skia.Win32.Win32WindowWrapper.OnPointer(uint msg, Windows.Win32.Foundation.WPARAM wParam, Windows.Win32.Foundation.HWND hwnd)	Unknown
 	Uno.UI.Runtime.Skia.Win32.dll!Uno.UI.Runtime.Skia.Win32.Win32WindowWrapper.WndProcInner(Windows.Win32.Foundation.HWND hwnd, uint msg, Windows.Win32.Foundation.WPARAM wParam, Windo...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes unoplatform/uno#22011

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for you](https://github.com/unoplatform/uno/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.

@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.

@unodevops
Copy link
Contributor

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

Copilot AI changed the title [WIP] Fix XamlReader.Load exception for custom markup extension fix: Support custom markup extensions in XamlReader.Load Dec 10, 2025
Copilot AI requested a review from nickrandolph December 10, 2025 02:50
@unodevops
Copy link
Contributor

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

@unodevops
Copy link
Contributor

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

@nickrandolph
Copy link
Contributor

@copilot fix test error:

Error message

View

Copy
System.InvalidOperationException: Exception thrown while invoking Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Markup.Given_XamlReader.When_MarkupExtension_ServiceProvider_InlineLiteral() with arguments { }.
---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> Uno.Xaml.XamlParseException: Failed to parse member (Failed to process custom markup extension 'DebugMarkupExtension'. [Line: 3 Position: 5]) [Line: 3 Position: 5]
---> Uno.Xaml.XamlParseException: Failed to process custom markup extension 'DebugMarkupExtension'. [Line: 3 Position: 5]
---> System.InvalidOperationException: Unable to find setter for property [Microsoft.UI.Xaml.Controls.UIElementCollection Children]
at Microsoft.UI.Xaml.Markup.Reader.XamlObjectBuilder.GetPropertySetter(PropertyInfo propertyInfo) in D:\a\1\s\src\Uno.UI\UI\Xaml\Markup\Reader\XamlObjectBuilder.cs:line 947
at Microsoft.UI.Xaml.Markup.Reader.XamlObjectBuilder.ProcessCustomMarkupExtension(Object instance, Object rootInstance, XamlMemberDefinition member, PropertyInfo propertyInfo) in D:\a\1\s\src\Uno.UI\UI\Xaml\Markup\Reader\XamlObjectBuilder.cs:line 1052
--- End of inner exception stack trace ---
at Microsoft.UI.Xaml.Markup.Reader.XamlObjectBuilder.ProcessCustomMarkupExtension(Object instance, Object rootInstance, XamlMemberDefinition member, PropertyInfo propertyInfo) in D:\a\1\s\src\Uno.UI\UI\Xaml\Markup\Reader\XamlObjectBuilder.cs:line 1063
at Microsoft.UI.Xaml.Markup.Reader.XamlObjectBuilder.ProcessMemberMarkupExtension(Object instance, Object rootInstance, XamlMemberDefinition member, PropertyInfo propertyInfo) in D:\a\1\s\src\Uno.UI\UI\Xaml\Markup\Reader\XamlObjectBuilder.cs:line 962
at Microsoft.UI.Xaml.Markup.Reader.XamlObjectBuilder.ProcessNamedMember(XamlObjectDefinition control, Object instance, XamlMemberDefinition member, Object rootInstance, TemplateMaterializationSettings settings) in D:\a\1\s\src\Uno.UI\UI\Xaml\Markup\Reader\XamlObjectBuilder.cs:line 526
at Microsoft.UI.Xaml.Markup.Reader.XamlObjectBuilder.LoadObject(XamlObjectDefinition control, Object rootInstance, Object component, TemplateMaterializationSettings settings, MemberInitializationContext memberContext, Boolean createInstanceFromXClass) in D:\a\1\s\src\Uno.UI\UI\Xaml\Markup\Reader\XamlObjectBuilder.cs:line 363
--- End of inner exception stack trace ---
at Microsoft.UI.Xaml.Markup.Reader.XamlObjectBuilder.Build(Object component, Boolean createInstanceFromXClass) in D:\a\1\s\src\Uno.UI\UI\Xaml\Markup\Reader\XamlObjectBuilder.cs:line 124
at Microsoft.UI.Xaml.Markup.XamlReader.Load(String xaml) in D:\a\1\s\src\Uno.UI\UI\Xaml\Markup\XamlReader.cs:line 15
at Uno.UI.Helpers.XamlHelper.LoadXaml[T](String xaml, Dictionary`2 xmlnses) in D:\a\1\s\src\Uno.UI\Helpers\XamlHelper.cs:line 74
at Uno.UI.Helpers.XamlHelper.LoadXaml[T](String xaml, Boolean autoInjectXmlns) in D:\a\1\s\src\Uno.UI\Helpers\XamlHelper.cs:line 58
at Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Markup.Given_XamlReader.When_MarkupExtension_ServiceProvider_InlineLiteral() in D:\a\1\s\src\Uno.UI.RuntimeTests\Tests\Windows_UI_Xaml_Markup\Given_XamlReader.cs:line 593
at InvokeStub_Given_XamlReader.When_MarkupExtension_ServiceProvider_InlineLiteral(Object, Object, IntPtr*)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
--- End of inner exception stack trace ---
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Uno.UI.Samples.Tests.UnitTestsControl.InvokeMethod(MethodInfo method, Object instance, Object[] methodArguments) in D:\a\1\s\src\SamplesApp\SamplesApp.UnitTests.Shared\Controls\UnitTest\UnitTestsControl.cs:line 1149
--- End of inner exception stack trace ---
at Uno.UI.Samples.Tests.UnitTestsControl.InvokeMethod(MethodInfo method, Object instance, Object[] m

Copy link
Contributor Author

Copilot AI commented Dec 19, 2025

@copilot fix test error:

Error message
...

Fixed in commit e775744. The issue was that collection properties like Panel.Children don't have setters. Added logic to check TypeResolver.IsInitializedCollection and use the Add method to add the markup extension result to the collection instead of trying to set the property value.

@unodevops
Copy link
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22073/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-22073/docs/index.html

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants