maui: XAMLC error when building an app with AoT compilation

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


About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 18 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Look like this bug is blocking CommunityToolkit new release. Hope you’ll find a way to fix that ! ❤️

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.

@jonathanpeppers @StephaneDelcroix @PureWeen Guys please tell us whether we should wait or kiss .NET 9 goodbye and wait for .NET 10 to be able to make an decent update. No word so far to when this is going to be fixed? As you can see this bug is now officially blocking updating most of the MAUI apps out there.

Look like this bug is blocking CommunityToolkit new release. Hope you’ll find a way to fix that ! ❤️

I also hope that. It’s blocking my release and my migration to .NET 9.0 as well 😕

Any word from the MAUI team in regards to when this will finally happen would be nice for us poor developers 😃

Oh great thanks. Perhaps I will see if I can reproduce the issue under test and then it would help to prove the fix is right 👍

thanks for the investigation. could you please provide a really simple sample that doesn’t depend on the toolkit, so we can generate a unit test, investigate, fix the issue, and make sure it doesn’t regress ? thanks

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?