dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.24k stars 1.76k forks source link

XAMLC error when building an app with AoT compilation #25871

Open pictos opened 13 hours ago

pictos commented 13 hours ago

Description

When building an app using AoT in release mode it breaks during build with the error message:

C:\Users\userName.nuget\packages\microsoft.maui.controls.build.tasks\9.0.10\buildTransitive\netstandard2.0\Microsoft.Maui.Controls.targets(171,3): Member 'System.IComparable' is declared in another module and needs to be imported [\MCT\samples\CommunityToolkit.Maui.Sample\CommunityToolkit.Maui.Sample.csproj]

Steps to Reproduce

  1. Run the sample project on the toolkit repo (be sure to that you're on feature/sl-dotnet-nine branch
  2. open the terminal and go to \samples\CommunityToolkit.Maui.Sample
  3. run, on terminal, dotnet build -c Release -bl
  4. See the message error

Binlog: msbuild.zip

Link to public reproduction project repository

https://github.com/CommunityToolkit/Maui/tree/feature/sl-dotnet-nine

Version with bug

9.0.10 SR1

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.100 SR10

Affected platforms

iOS, Android, Windows, macOS

Affected platform versions

All versions

Did you find any workaround?

N/A

Relevant log output

jonathanpeppers commented 11 hours ago

This seems unrelated to AOT, the <XamlCTask/> is failing to write an assembly, Mono.Cecil is giving this error:

If you use System.IComparable in your assembly somewhere, does it fix it? I think you could literally just make a method that isn't called?

brminnick commented 11 hours ago

If you use System.IComparable in your assembly somewhere, does it fix it? I think you could literally just make a method that isn't called?

Yes, we use IComparable in the CommunityToolkit.Maui library.

I tried implementing IComaprable in the CommunityToolkit.Maui.Sample sample app and it did not solve the build error.

jonathanpeppers commented 11 hours ago

Do you know what specific XAML file (or element) causes the problem?

brminnick commented 10 hours ago

I don't know for sure; I can only guess.

Here is where we are using IConverter in CommunityToolkit.Maui for CompareConverter: https://github.com/CommunityToolkit/Maui/blob/0e991c2cc08791a6fbf5fdc909714ba2537a0ee6/src/CommunityToolkit.Maui/Converters/CompareConverter.shared.cs

And here is where we are demo'ing CompareConverter in CommunityToolkit.Maui.Sample: https://github.com/CommunityToolkit/Maui/blob/0e991c2cc08791a6fbf5fdc909714ba2537a0ee6/samples/CommunityToolkit.Maui.Sample/Pages/Converters/CompareConverterPage.xaml

bijington commented 1 hour ago

I have performed some investigations this morning and I believe I can pinpoint the specific usage that is causing this. We see the error being reported from this line

https://github.com/CommunityToolkit/Maui/blob/e46c39e5f311df772edcdeb235f64c605160ed3e/samples/CommunityToolkit.Maui.Sample/Views/Popups/UpdatingPopup.xaml#L44

If I comment the above line out then the project will compile. Note that this inside a Popup.

Furthermore if I take that same binding and place it in here https://github.com/CommunityToolkit/Maui/blob/main/samples/CommunityToolkit.Maui.Sample/Pages/Converters/CompareConverterPage.xaml changing the property to SliderValue and the namespace to mct then the code will happily compile. Note that this inside a ContentPage.

I suspect that the XAMLC is somehow not performing the same tasks for our Popup XAML that it is for ContentPage XAML.

In case it helps for the context of finding the issue I can workaround the problem by creating a subclass of our CompareConverter e.g.

using CommunityToolkit.Maui.Converters;

namespace CommunityToolkit.Maui.Sample.Converters;

/// <summary>
/// Compares a double value against the ComparingValue property
/// and returns a <see cref="bool"/> based on the comparison.
/// </summary>
[AcceptEmptyServiceProvider]
public sealed partial class CompareDoubleToBooleanConverter : CompareConverter<double, bool>
{
}

and then using this in the UpdatingPopup.xaml file.