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

Support .NET 9.0 #2215

Open
wants to merge 176 commits into
base: main
Choose a base branch
from
Open

Support .NET 9.0 #2215

wants to merge 176 commits into from

Conversation

bijington
Copy link
Contributor

@bijington bijington commented Sep 18, 2024

Description of Change

Linked Issues

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Documentation created or updated: https://github.com/MicrosoftDocs/CommunityToolkit/pulls

Breaking Changes

Major Breaking Changes

  • .NET 8 no longer supported
  • Xcode 16.1 Required
  • Stop automatically assigning Behavior.BindingContext
    • .NET MAUI Behaviors do not automatically inherit their parent's BindingContext (a breaking change from Xamarin.Forms)
    • Going forward, the .NET MAUI Community Toolkit will follow this implementation of Behaviors
  • Increase minimum supported OS versions of CommunityToolkit.Maui.MediaElement
    • Android 26.0
    • iOS 15.0
    • MacCatalyst 15.0
  • Increase minimum supported versions of CommunityToolkit.Maui.Camera to 15.0:
    • iOS 15.0
    • MacCatalyst 15.0

Minor Breaking Changes

  • Expander is not trim safe
  • ValidationBehaviors are not trim safe
  • CommunityToolkit.Maui.Maps is not trim safe
  • Remove PopupService.ShowPopop(TViewModel)
    • Removes [Obsolete] method
    • Use PopupService.ShowPopup<T>() instead
  • Remove PopupService.ShowPopopAsync(TViewModel, CancellationToken)
    • Removes [Obsolete] method
    • Use PopupService.ShowPopupAsync<T>() instead
  • Remove ability to subclass BaseConverter<TFrom, TTo>
    • Subclassing from BaseConverter<TFrom, TTo> is not supported
    • Support requires documentation and complete unit tests
  • Remove ability to subclass BaseConverter<TFrom, TTo, TParam>
    • Subclassing from BaseConverter<TFrom, TTo, TParam> is not supported
    • Support requires documentation and complete unit tests
  • ValidationFlags.ValidateOnFocusing renamed to ValidationFlags.ValidateOnFocused
  • ValidationFlags.ValidateOnUnfocusing renamed to ValidationFlags.ValidateOnUnfocused
  • In CommunityToolkit.Maui.Camera, add linker.xml for net9.0-android to avoid the Linker removing Xamarin.AndroidX.Camera.Core, Xamarin.AndroidX.Camera.Lifecycle, Xamarin.AndroidX.Camera.Video, Xamarin.AndroidX.Camera.View, and Xamarin.AndroidX.Camera.Camera2
  • public static Task<bool> ShowKeyboardAsync(this ITextInput, CancellationToken) -> public static ValueTask<bool> ShowKeyboardAsync(this ITextInput, CancellationToken)
  • NuGet package will not support Microsoft.Maui.Controls .NET 10 until .NET 10 GA

Analyzer Benchmarks

.NET 9.0 Mean Error StdDev Median Gen0 Gen1 Allocated
VerifyNoErrorsWhenUseMauiCommunityToolkit 8.863 ms 0.1748 ms 0.3240 ms 8.724 ms 62.5000 31.2500 1.59 MB
VerifyNoErrorsWhenUseMauiCommunityToolkitHasAdditionalWhitespace 8.695 ms 0.1654 ms 0.4358 ms 8.528 ms 62.5000 31.2500 1.59 MB
VerifyErrorsWhenMissingUseMauiCommunityToolkit 12.071 ms 0.3756 ms 1.0470 ms 11.546 ms 66.6667 - 2.29 MB
.NET 8.0 Mean Error StdDev Median Gen0 Allocated
VerifyNoErrorsWhenUseMauiCommunityToolkitMediaElement 9.763 ms 0.1928 ms 0.4765 ms 9.633 ms 31.2500 1.46 MB
VerifyNoErrorsWhenUseMauiCommunityToolkitMediaElementHasAdditonalWhitespace 9.565 ms 0.1862 ms 0.4637 ms 9.460 ms 31.2500 1.46 MB
VerifyErrorsWhenMissingUseMauiCommunityToolkitMediaElement 15.495 ms 0.3879 ms 1.0814 ms 15.058 ms 66.6667 2.24 MB

@hansmbakker
Copy link

hansmbakker commented Sep 18, 2024

The errors are because in https://github.com/CommunityToolkit/Maui/blob/feature/sl-dotnet-nine/azure-pipelines.yml the .NET SDK to install is

  • set to the LATEST_NET_VERSION variable instead of picking up the version from global.json
  • set to prevent using prereleases (both in global.json and in azure-pipelines.yml)

See

Maui/azure-pipelines.yml

Lines 73 to 78 in c4169ed

- task: UseDotNet@2
displayName: 'Install Latest .NET SDK, v$(LATEST_NET_VERSION)'
inputs:
packageType: 'sdk'
version: '$(LATEST_NET_VERSION)'
includePreviewVersions: false

Note that the UseDotNet@2 task can pick up global.json to read its settings from - I would recommend to define these SDK settings only in global.json and not redefining it in the pipeline as well.

Copy link
Collaborator

@brminnick brminnick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the Analyzer Unit Tests, Shaun! We can just remove the reference to Net80 since we won't be reverting back to .NET 8 after we update the library to .NET 9.

bijington and others added 2 commits September 19, 2024 20:23
…AnalyzerVerifier`1+Test.cs

Co-authored-by: Brandon Minnick <[email protected]>
…CodeFixVerifier`2+Test.cs

Co-authored-by: Brandon Minnick <[email protected]>
@bijington
Copy link
Contributor Author

The errors are because in https://github.com/CommunityToolkit/Maui/blob/feature/sl-dotnet-nine/azure-pipelines.yml the .NET SDK to install is

  • set to the LATEST_NET_VERSION variable instead of picking up the version from global.json
  • set to prevent using prereleases (both in global.json and in azure-pipelines.yml)

See

Maui/azure-pipelines.yml

Lines 73 to 78 in c4169ed

- task: UseDotNet@2
displayName: 'Install Latest .NET SDK, v$(LATEST_NET_VERSION)'
inputs:
packageType: 'sdk'
version: '$(LATEST_NET_VERSION)'
includePreviewVersions: false

Note that the UseDotNet@2 task can pick up global.json to read its settings from - I would recommend to define these SDK settings only in global.json and not redefining it in the pipeline as well.

Thanks for the suggestions. I know we have been discussing about migrating to GitHub actions so I will leave this with limited change for now

@bijington
Copy link
Contributor Author

Things are looking very positive: dotnet/maui#26303 (comment)

@MauiUIui
Copy link

MauiUIui commented Dec 5, 2024

Things are looking very positive: dotnet/maui#26303 (comment)

Thanks man. Good news :)
Can we say that a nuget update is a day or so away?

@bijington
Copy link
Contributor Author

Things are looking very positive: dotnet/maui#26303 (comment)

Thanks man. Good news :)

Can we say that a nuget update is a day or so away?

We can say that an update is a day or so away once we receive the official .NET MAUI nuget containing the fix. My test build was against the MAUI nightly feed and I believe we are waiting on SR2 to be released. I am hopeful the release is imminent

@MauiUIui
Copy link

MauiUIui commented Dec 5, 2024

Things are looking very positive: dotnet/maui#26303 (comment)

Thanks man. Good news :)
Can we say that a nuget update is a day or so away?

We can say that an update is a day or so away once we receive the official .NET MAUI nuget containing the fix. My test build was against the MAUI nightly feed and I believe we are waiting on SR2 to be released. I am hopeful the release is imminent

Thx mate. Appreciate the good work :)

@brminnick brminnick removed the blocked label Dec 12, 2024
Copy link
Collaborator

@brminnick brminnick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are officially unblocked as Microsoft.Maui.Controls v9.0.21 contains the bug fix for the blocker.

@brminnick
Copy link
Collaborator

brminnick commented Dec 12, 2024

Dang - there is a new error:

ILLink : error IL1012: IL Trimmer has encountered an unexpected error. Please report the issue at https://aka.ms/report-illink [/Users/runner/work/1/s/samples/CommunityToolkit.Maui.Sample/CommunityToolkit.Maui.Sample.csproj::TargetFramework=net9.0-maccatalyst

https://dev.azure.com/dotnet/CommunityToolkit/_build/results?buildId=112518&view=logs&j=17b0f84d-e186-52d3-858a-533c8ddf3c8c&t=670b1d62-8fe8-5e0d-0040-71e96d237771&l=992

I'll re-add the blocked label while we investigate.

@pictos
Copy link
Member

pictos commented Dec 14, 2024

During investigation I found that error is caused by a failing MSBuild task, so I reported the issue to the dotnet runtime, hopefully they can fix it and/or provide a guidance

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 431 out of 446 changed files in this pull request and generated no comments.

Files not reviewed (15)
  • .editorconfig: Language not supported
  • Directory.Build.props: Language not supported
  • global.json: Language not supported
  • samples/CommunityToolkit.Maui.Sample/AppShell.xaml: Language not supported
  • samples/CommunityToolkit.Maui.Sample/CommunityToolkit.Maui.Sample.csproj: Language not supported
  • samples/CommunityToolkit.Maui.Sample/Pages/Alerts/SnackbarPage.xaml: Language not supported
  • samples/CommunityToolkit.Maui.Sample/Pages/Behaviors/AnimationBehaviorPage.xaml: Language not supported
  • samples/CommunityToolkit.Maui.Sample/Pages/Behaviors/CharactersValidationBehaviorPage.xaml: Language not supported
  • samples/CommunityToolkit.Maui.Sample/Pages/Behaviors/EmailValidationBehaviorPage.xaml: Language not supported
  • samples/CommunityToolkit.Maui.Sample/App.xaml.cs: Evaluated as low risk
  • samples/CommunityToolkit.Maui.Sample/Pages/Alerts/AlertsGalleryPage.cs: Evaluated as low risk
  • samples/CommunityToolkit.Maui.Sample/Pages/Alerts/SnackbarPage.xaml.cs: Evaluated as low risk
  • samples/CommunityToolkit.Maui.Sample/Pages/Behaviors/AnimationBehaviorPage.xaml.cs: Evaluated as low risk
  • samples/CommunityToolkit.Maui.Sample/Pages/Base/BaseGalleryPage.cs: Evaluated as low risk
  • samples/CommunityToolkit.Maui.Sample/Converters/CompareDoubleToColorConverter.cs: Evaluated as low risk
@espenrl
Copy link

espenrl commented Dec 15, 2024

This is the exception from the build log above

https://dev.azure.com/dotnet/CommunityToolkit/_build/results?buildId=112518&view=logs&j=17b0f84d-e186-52d3-858a-533c8ddf3c8c&t=670b1d62-8fe8-5e0d-0040-71e96d237771&l=992

ILLink : error IL1012: IL Trimmer has encountered an unexpected error. Please report the issue at https://aka.ms/report-illink [/Users/runner/work/1/s/samples/CommunityToolkit.Maui.Sample/CommunityToolkit.Maui.Sample.csproj::TargetFramework=net9.0-maccatalyst]
  Fatal error in IL Linker
  Unhandled exception. System.IndexOutOfRangeException: Index was outside the bounds of the array.
     at System.Collections.Immutable.ImmutableArray`1.get_Item(Int32 index)
     at Mono.Linker.Dataflow.TrimAnalysisMethodCallPattern.Merge(ValueSetLattice`1 lattice, TrimAnalysisMethodCallPattern other)
     at Mono.Linker.Dataflow.TrimAnalysisPatternStore.Add(TrimAnalysisMethodCallPattern pattern)
     at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.HandleCall(MethodBody callingMethodBody, MethodReference calledMethod, Instruction operation, ValueNodeList methodParams)
     at Mono.Linker.Dataflow.MethodBodyScanner.HandleCall(MethodBody callingMethodBody, Instruction operation, Stack`1 currentStack, Dictionary`2 locals, InterproceduralState& interproceduralState, Int32 curBasicBlock)
     at Mono.Linker.Dataflow.MethodBodyScanner.Scan(MethodIL methodIL, InterproceduralState& interproceduralState)
     at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.Scan(MethodIL methodIL, InterproceduralState& interproceduralState)
     at Mono.Linker.Dataflow.MethodBodyScanner.InterproceduralScan(MethodIL startingMethodIL)
     at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.InterproceduralScan(MethodIL methodIL)
     at Mono.Linker.Steps.MarkStep.MarkReflectionLikeDependencies(MethodIL methodIL, Boolean requiresReflectionMethodBodyScanner, MessageOrigin origin)
     at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body, MessageOrigin origin)
     at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method, DependencyInfo& reason)
     at Mono.Linker.Steps.MarkStep.ProcessQueue()
     at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
     at Mono.Linker.Steps.MarkStep.Process()
     at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
     at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
     at Mono.Linker.Pipeline.Process(LinkContext context)
     at Mono.Linker.Driver.Run(ILogger customLogger)
     at Mono.Linker.Driver.Main(String[] args)

And the code can be found here

https://github.com/dotnet/runtime/blob/main/src/tools/illink/src/linker/Linker.Dataflow/TrimAnalysisMethodCallPattern.cs#L45

@bijington
Copy link
Contributor Author

@espenrl please add the detail to the issue opened at dotnet/runtime#110714

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment