dotnet icon indicating copy to clipboard operation
dotnet copied to clipboard

Adding version 8.2.2 to existing Maui project breaks xaml file(s)

Open rkreisel opened this issue 1 year ago • 1 comments

Describe the bug

I had a working project using the that was not using the CommunityToolkit. <ItemGroup> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" /> <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.21" /> <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.21" /> <PackageReference Include="Microsoft.Maui.Essentials" Version="8.0.21" /> <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.5.1" /> </ItemGroup>

It built and ran fine. I added the CommunityToolkit <ItemGroup> <PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" /> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" /> <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.21" /> <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.21" /> <PackageReference Include="Microsoft.Maui.Essentials" Version="8.0.21" /> <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.5.1" /> </ItemGroup>

and now the build throws this error: "Input string was not in the correct format" It points to line 1 of the mainpage.xaml file.

Regression

No response

Steps to reproduce

.net 8
Maui project 
VS 2022
Fairly simple app that retrieves information from a web service and formats it on the device.
Ensure it works without the toolkit. 

Add the toolkit and attempt to build.
I get the error noted above.

Add the following to the main page.
<ContentPage
other stuff...
xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit">
    <ContentPage.Behaviors>
        <mct:EventToCommandBehavior Command="{Binding AppearingCommand}" EventName="Appearing" />
    </ContentPage.Behaviors>

... other xaml
</ContentPage>

<ContentPage.Behaviors>
        <mct:EventToCommandBehavior Command="{Binding AppearingCommand}" EventName="Appearing" />
    </ContentPage.Behaviors>

Try the build again to get the message telling you to change the startup.

Change the MauiProgram start to include the toolkit:
	public static MauiApp CreateMauiApp()
	{
		var builder = MauiApp.CreateBuilder();
		builder
			.UseMauiApp<App>()
			.ConfigureFonts(fonts =>
			{
				fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
			});
		builder.Services.Add... blah blah blah other services
        return builder.Build();
	}

Build again - get an error telling you you need implement the target method in the viewmodel.cs
Implement it per the instructions here: https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/behaviors/event-to-command-behavior

Build again and get the original error.

Expected behavior

I was trying to implement loading of the data when the app starts, but cannot get past the xml error. So the expected behavior would have been to load the data when the app started.

Screenshots

No response

IDE and version

VS 2022

IDE version

Version 17.9.6

Nuget packages

  • [ ] CommunityToolkit.Common
  • [ ] CommunityToolkit.Diagnostics
  • [ ] CommunityToolkit.HighPerformance
  • [ ] CommunityToolkit.Mvvm (aka MVVM Toolkit)

Nuget package version(s)

see the bug description above where I pasted in the references

Additional context

I have to caveat this problem with telling you that is is my first Maui app outside of a class. So, I quite possibly am missing something very basic.

Help us help you

Yes, but only if others can assist

rkreisel avatar May 07 '24 20:05 rkreisel

Hmmm, The stuff I pasted into the bug description area does not seem to have been included. I'll try again.

xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"

<ContentPage.Behaviors> <mct:EventToCommandBehavior Command="{Binding AppearingCommand}" EventName="Appearing" /> </ContentPage.Behaviors>

PackageReference Include="CommunityToolkit.Maui" Version="9.0.0" /> PackageReference Include="CommunityToolkit.Maui.Core" Version="9.0.0" /> PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" /> PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" /> PackageReference Include="Microsoft.Maui.Controls" Version="8.0.21" /> PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.21" /> PackageReference Include="Microsoft.Maui.Essentials" Version="8.0.21" /> PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.5.1" />

rkreisel avatar May 07 '24 20:05 rkreisel