Skip to content

XAML generator aliases _View to a native view type, breaking FrameworkTemplate builders on mobile (CS0407) #24459

Closed

Description

@MartinZikmund

Current behavior

A library that references Uno.WinUI from a plain <Project Sdk="Microsoft.NET.Sdk"> cannot compile any XAML template on a mobile target framework:

error CS0407: 'View GlobalStaticResources.ResourceDictionarySingleton__mergedpages_<hash>
    .Build_ResDicΞ204_StyΞ16_Set_ValΞ0_ConTem(object, TemplateMaterializationSettings)'
    has the wrong return type          (net10.0-android)

error CS0407: 'UIView ...same shape...' has the wrong return type   (net10.0-ios)

Root cause

XamlFileGenerator.cs (lines 347-355 at 611bb279f9) emits a platform-conditional alias that predates the removal of native view rendering:

#if HAS_UNO_SKIA
using _View = Microsoft.UI.Xaml.UIElement;
#elif __ANDROID__
using _View = Android.Views.View;
#elif __APPLE_UIKIT__ || __IOS__ || __TVOS__
using _View = UIKit.UIView;
#else
using _View = Microsoft.UI.Xaml.UIElement;
#endif

_View is the return type of every generated FrameworkTemplate builder (chosen at :6489, used at :6536 and :1037). Those builders are converted to Uno.UI.FrameworkTemplateBuilder at :6552, and that delegate returns UIElement (src/Uno.UI/Uno/FrameworkTemplateBuilder.cs:15). In 7.0 UIElement derives from DependencyObject and is unrelated to Android.Views.View / UIKit.UIView, so the method-group conversion is illegal.

Both native branches are dead — Uno.WinUI 7.0 ships no android or ios assembly, so they can only produce output that fails to compile.

Why CI does not catch it

HAS_UNO_SKIA comes from Uno.WinUI.Runtime.Skia.Android / .AppleUIKit, which ship it from build/ rather than buildTransitive/ — so it applies to a direct reference only, and the Uno SDK adds that reference with PrivateAssets="all". Every project in this repo, and every Uno.Sdk project, therefore takes the first branch. A plain Microsoft.NET.Sdk library never gets the constant, and Uno.WinUI's nuspec has no android/ios dependency group through which it could arrive.

The snapshot tests compare generated text and embed the #if/#elif verbatim, so they pass on any platform.

Reproduction

Uno.Simple.WinUI in unoplatform/Uno.Themes#1722 — the one library there not on the Uno SDK. Fails on net10.0-android and net10.0-ios; its three siblings, which use Uno.Sdk.Private, build fine on the same TFMs.

Isolation experiment confirming the cause: defining HAS_UNO_SKIA on that library takes it from 4 × CS0407 to 0 errors on net10.0-android.

Expected behavior

XAML templates compile on every target framework regardless of which SDK the consuming project uses.

Fix

PR #24457 — collapse the alias to using _View = Microsoft.UI.Xaml.UIElement; unconditionally. The two branches taken today already emit exactly that line, so no configuration that builds today changes a single generated character.

Environment

Uno.Sdk.Private / Uno.WinUI 7.0.0-dev.679; also present on master at 611bb279f9.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions