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

Getting a XamlC error when trying to use common xmlns only in XAML without x:Name #7503

Closed
vvgeorgiev opened this issue May 26, 2022 · 12 comments
Assignees
Labels
area-xaml XAML, CSS, Triggers, Behaviors p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint partner Issue or Request from a partner team platform/android 🤖 platform/iOS 🍎 platform/macOS 🍏 macOS / Mac Catalyst platform/windows 🪟 s/try-latest-version Please try to reproduce the potential issue on the latest public version t/bug Something isn't working
Milestone

Comments

@vvgeorgiev
Copy link

Description

I am creating custom controls in a library assembly. I have added XmlnsDefinition for the corresponding namespaces. If I use the controls in XAML and if I do not set x:Name, I get the following compile time error:
XamlC error XFC0000: Cannot resolve type "http://schemas.mycompany.com/2022/xaml/maui:prefix:MyControl".
If I set x:Name in the page, where the controls are used -- it works, if I use the controls in code behind in addition to XAML -- it works.

Steps to Reproduce

  1. Rebuild the attached solution
  2. Observe the error:
    XamlC error XFC0000: Cannot resolve type "http://schemas.mycompany.com/2022/xaml/maui:prefix:MyControl"
    MauiXmlnsRepro.zip

Version with bug

6.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, Windows, macOS

Affected platform versions

N/A - compile-time issue

Did you find any workaround?

Setting x:Name in the page fixes it, but it is outside my control as a component vendor.

Relevant log output

No response

@vvgeorgiev vvgeorgiev added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels May 26, 2022
@jsuarezruiz jsuarezruiz added area-xaml XAML, CSS, Triggers, Behaviors partner Issue or Request from a partner team labels May 26, 2022
@StephaneDelcroix
Copy link
Contributor

Looks like a linking issue. Adding x:Name creates a ref that prevents linking out. I’ll investigate further

@VincentBu
Copy link

repro with vs main build(32606.310.main)

@VincentBu VincentBu added s/verified Verified / Reproducible Issue ready for Engineering Triage and removed s/needs-verification Indicates that this issue needs initial verification before further triage will happen labels Jun 7, 2022
@StephaneDelcroix
Copy link
Contributor

not a trimming/linking option.

@pictos
Copy link
Contributor

pictos commented Jun 7, 2022

Maybe this can help...
Just a reminder, in order to use the custom-schema, generated by XmlnsDefinition you need to have some C# code that references the lib. More info here.

After adding _ = new RadButton(); _ = new RadGauge(); in the code (I added on the MauiProgram) I was able to run, but for some reason the RadioButton still fails, not sure if it's because you have the same custom schema for two different assemblies

i was adding RadioButton instead of RadButton, after fixing that it worked (:
So I would say that isn't a bug, but a limitation on custom XmlnsDefinition

@StephaneDelcroix
Copy link
Contributor

The workaround pointed by @pictos works: adding a code reference to each assembly (not each type) solve the issue. But the intent of this workaround, and documentation, was to prevent linking for runtime-inflated Xaml. With Maui, Xaml Compilation is enforced for Release builds, and we could get rid of this requirement.

So, not a new error, but I'm still investigating if we can get rid of it...

@bijington
Copy link

@StephaneDelcroix if you can improve on this issue that would be fantastic. I have seen a few projects where people make use of the .NET MAUI Community Toolkit via library projects and without C# directly accessing the components they need they see this issue.

I would be more than happy to provide any details/assistance on this.

@ghost
Copy link

ghost commented Aug 30, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@mrlacey
Copy link
Contributor

mrlacey commented Jan 29, 2023

Also get this if use a Map with no other properties set.

e.g.:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
			 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
			 xmlns:vm="clr-namespace:EmulatorApp6.ViewModels"
			 x:Class="EmulatorApp6.Views.MapPage"
			 x:DataType="vm:MapViewModel">

	<Map />
</ContentPage>
1>        Done building project "App6.csproj" -- FAILED.
1>        Views\MapPage.xaml(8,3): XamlC error XFC0000: Cannot resolve type "http://schemas.microsoft.com/dotnet/2021/maui:Map".

@samhouts samhouts added p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint and removed p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint labels Feb 3, 2023
@NasTheRobotKing
Copy link

I also get this issue all over the place after converting my .NET Xamarin project to MAUI. Any resolution?

image

@jonathanpeppers
Copy link
Member

I tried the original example (upgraded to .NET 7):

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:telerik="http://schemas.telerik.com/2022/xaml/maui"
             x:Class="MauiApp14.MainPage">
    <Grid>
        <telerik:RadButton></telerik:RadButton>
        <telerik:RadGauge></telerik:RadGauge>
    </Grid>
</ContentPage>

And XamlC emits this in Release mode on Android:

private void InitializeComponent()
{
	RadButton radButton = new RadButton();
	RadGauge radGauge = new RadGauge();
	Grid grid = new Grid();
	MainPage mainPage;
	NameScope value = (NameScope)(NameScope.GetNameScope(mainPage = this) ?? new NameScope());
	NameScope.SetNameScope(mainPage, value);
	grid.Children.Add(radButton);
	grid.Children.Add(radGauge);
	mainPage.SetValue(ContentPage.ContentProperty, grid);
}

Which looks right to me.

But then I get a crash at runtime because the handler is missing:

04-13 16:52:39.305  8175  8175 I MonoDroid: android.runtime.JavaProxyThrowable: Microsoft.Maui.Platform.HandlerNotFoundException: Handler not found for view MauiLib.Controls.RadButton.

So yeah, there might be something fundamental here. Why is MauiLib.Controls.dll even trimmed at all in this example?

@jonathanpeppers
Copy link
Member

Oh, Debug mode crashes in the same way. Does someone have a more recent repro?

I am not getting a XamlC error using the latest stable MAUI.

@jonathanpeppers jonathanpeppers added the s/try-latest-version Please try to reproduce the potential issue on the latest public version label Apr 13, 2023
@ghost
Copy link

ghost commented Apr 13, 2023

Hi @vvgeorgiev. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

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.

@ghost ghost closed this as completed Apr 21, 2023
@ghost ghost locked as resolved and limited conversation to collaborators May 21, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-xaml XAML, CSS, Triggers, Behaviors p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint partner Issue or Request from a partner team platform/android 🤖 platform/iOS 🍎 platform/macOS 🍏 macOS / Mac Catalyst platform/windows 🪟 s/try-latest-version Please try to reproduce the potential issue on the latest public version t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests