Skip to content

Strict type resolution fails when namespace is not on the top-level element #14161

Closed

Description

@jeromelaban

Current behavior

The following xaml fails when UnoEnableXamlFuzzyMatching is set to false:

      <embed:MauiHost x:Name="MauiHostElement"
              xmlns:embed="using:Uno.Extensions.Maui"
              xmlns:controls="using:Uno5TestMauiEmbed01.MauiControls"
              Source="controls:EmbeddedControl" />

embed:MauiHost is considered as not available when building.

Expected behavior

The compilation succeeds,

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

No response

Workaround

Move the namespace controls definition on the root element of the file.

Works on UWP/WinUI

None

Environment

No response

NuGet package version(s)

5.0-dev

Affected platforms

No response

IDE

No response

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

No response

Activity

  1. added
    kind/bug
    triage/untriaged
    difficulty/tbd
    on Oct 28, 2023
  2. added a commit that references this issue on Oct 29, 2023
  3. Youssef1313 commented on Oct 30, 2023

    @Youssef1313
    Member

    In general, the generator is able to figure out the namespace when it's not in top-level element.

    The following test is passing:

    	[TestMethod]
    	public async Task When_Namespace_Is_On_Nested_Element()
    	{
    		var xamlFiles = new[]
    		{
    			new XamlFile(
    				"MainPage.xaml",
    				"""
    				<Page x:Class="TestRepro.MainPage"
    					  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    					  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    					  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
    
    					<Grid>
    
    						<local:MyStackPanel xmlns:local="using:TestRepro" />
    
    					</Grid>
    				</Page>
    				"""),
    		};
    
    		var test = new Verify.Test(xamlFiles)
    		{
    			TestState =
    			{
    				Sources =
    				{
    					"""
    					using Windows.UI.Xaml.Controls;
    
    					namespace TestRepro
    					{
    
    						public sealed partial class MyStackPanel : StackPanel { }
    
    						public sealed partial class MainPage : Page
    						{
    							public MainPage()
    							{
    								this.InitializeComponent();
    							}
    						}
    					}
    					"""
    				}
    			}
    		}.AddGeneratedSources();
    
    		await test.RunAsync();
    	}

    So it's looking like there is something very specific going on here.

  4. Youssef1313 commented on Oct 30, 2023

    @Youssef1313
    Member

    @jeromelaban Based on the workaround you did, the problem isn't really about embed:MauiHost, it's about controls:EmbeddedControl which is referenced in Source="controls:EmbeddedControl"

  5. Youssef1313 commented on Oct 30, 2023

    @Youssef1313
    Member

    @jeromelaban

    private INamedTypeSymbol GetType(string name)
    {
    var type = _findType!(name);
    if (type == null)
    {
    throw new InvalidOperationException("The type {0} could not be found".InvariantCultureFormat(name));
    }
    return type;
    }

    We are calling GetType("controls:EmbeddedControl"), which has absolutely no context about the surrounding XAML and we use _fileDefinition.Namespaces for resolution in this code path.

    Looking closer, I think we will need to find a way to store namespaces as we encounter them here:

    case XamlNodeType.NamespaceDeclaration:
    lastWasLiteralInline = false;
    lastWasTrimSurroundingWhiteSpace = false;
    // Skip
    break;

  6. added
    area/code-generation
    difficulty/medium 🤔
    and removed
    triage/untriaged
    difficulty/tbd
    on Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/code-generationdifficulty/medium 🤔kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions