August 27th, 2024

.NET Community Toolkit 8.3 is here! NativeAOT, .NET 8 enhancements, and more!

Sergio Pedri
Senior Software Engineer

We’re happy to announce the official launch of the 8.3 release of the .NET Community Toolkit! This new version includes .NET 8 and NativeAOT support for all libraries, performance improvements, several bug fixes and enhancements, and more!

.NET Community Toolkit 8.3.0

As always, we deeply appreciate all the feedback received both by teams here at Microsoft using the Toolkit, as well as other developers in the community. All the issues, bug reports, comments and feedback continue to be extremely useful for us to plan and prioritize feature work across the entire .NET Community Toolkit. Thank you to everyone contributing to this project and helping make the .NET Community Toolkit better! 🎉

What’s in the .NET Community Toolkit? 👀

The .NET Community Toolkit includes the following libraries:

  • CommunityToolkit.Common
  • CommunityToolkit.Mvvm (aka “Microsoft MVVM Toolkit”)
  • CommunityToolkit.Diagnostics
  • CommunityToolkit.HighPerformance

These components are also widely used in several inbox apps that ship with Windows, such as the Microsoft Store and the Photos app! 🚀

For more details on the history of the .NET Community Toolkit, here is a link to our previous 8.0.0 announcement post.

Here is a breakdown of the main changes that are included in this new 8.3 release of the .NET Community Toolkit.

.NET 8 and NativeAOT support 🚀

The main change in this new release of the .NET Community Toolkit is support for .NET 8 and NativeAOT! As part of this, all APIs across all packages have been annotated to fully support trimming and AOT compatibility, to ensure using any part of the .NET Community Toolkit goes smoothly even in those scenarios. Here you can see an example of a new trim annotation, that correctly shows up in the IDE to warn about potentially unsafe code (even from code generated by [ObservableProperty]!):

Trim warning for validatable properties

Additionally, this new release of the MVVM Toolkit adds support for the net8.0-windows10.0.17763.0 target as well, to be fully trim and AOT compatible with WinAppSDK (WinUI 3) as well! Adding this new target framework is necessary to ensure that all types that might be marshalled to WinRT will have all needed interop code generated for them, via CsWinRT. This is all fully transparent for consumers of the package: just reference the MVVM Toolkit from any project, publish with NativeAOT, and it will work as expected!

Removing overhead for unused MVVM Toolkit features (ie. making it “more pay-for-play”) 🎈

This release also includes more performance improvements for the MVVM Toolkit. This time, the focus was on making the support for INotifyPropertyChanging fully pay-for-play: meaning that when this interface is not needed, there will be no additional overhead because of it. For instance, frameworks such as UWP and WinUI 3 don’t need viewmodels to implement this property. In those scenarios, you can set this in your .csproj file:

<PropertyGroup>
  <MvvmToolkitEnableINotifyPropertyChangingSupport>false</MvvmToolkitEnableINotifyPropertyChangingSupport>
</PropertyGroup>

When this property is set to false (it defaults to true for backwards compatibility), all code associated with INotifyPropertyChanging in ObservableObject will be trimmed out (the event will never be raised, and event args will never be allocated). Additionally, the MVVM Toolkit source generator will also detect and respect the value of this property, and it will optimize the code to avoid generating all the code that was meant to implement that functionality!

Other changes and improvements ✅

  • Fix generation for OnPropertyChanging for [NotifyPropertyChangedFor] (#722): when using [NotifyPropertyChangedFor], the generated OnPropertyChanging methods were not being invoked for dependent properties. This has now been fixed.
  • Include sizeof(T) in offset calculation for Memory2D<T> from MemoryManager (#841): creating a Memory2D<T> instance wrapping a MemoryManager incorrectly tracked the data offset. This is no longer the case, thank you @Lillenne!
  • Avoid auto-generating ObservableValidator.HasError (#844): the ObservableValidator.HasError property will no longer automatically show up in table views in frameworks that dynamically generate columns from declared properties. Thank you @arivoir!
  • Fix IBufferWriterExtensions.Write for unmanaged types (#799): fixed an incorrect length calculation in the Write extension for unmanaged types. Thank you @pziezio!

You can see the full changelog for this release from the GitHub release page.

Get started today! 🎉

You can find all source code in our GitHub repo, some handwritten docs on MS learn, and complete API references in the .NET API browser website. If you would like to contribute, feel free to open issues or to reach out to let us know about your experience! To follow the conversation on Twitter, use the #CommunityToolkit hashtag. All your feedback greatly helped shape the direction of these libraries, so make sure to share them!

Happy coding! 💻

Author

Sergio Pedri
Senior Software Engineer

I'm a Senior Software Engineer at Microsoft, working on the new Microsoft Store app for Windows 11 and Windows 10, and the maintainer of the .NET Community Toolkit, a suite of open source libraries to help all .NET developers. I started writing Windows and .NET apps in 2013 with Silverlight and later WinRT, and then moved to UWP. I'm passionate about open source software and a member of the .NET Foundation since 2020, and I regularly contribute to several projects on GitHub (such as ...

More about author

8 comments

  • Eric Gosselin

    It looks like there is a problem with the version 8.3 of the CommunityToolkit.Mvvm. I got this error when I tried to execute my application : “could not load file or assembly ‘winrt.runtime, version=2.1.0.0”. I had to downgrade to the previous version 8.2.2 to make it work.
    Thank You

  • Michael . · Edited

    from full changelog:

    Don't generate 'INotifyPropertyChanging' code if not requested by @Sergio0694

    could you please add to generate also if requested by me :o) ?

  • Brady Chambers

    thanks so much to you and everyone that contributed…. your work makes our work so much easier and better…..

  • Rand Random

    I don’t really understand the claim „NativeAOT support“ when you are showcasing a case where its not supported and gives warnings, and not even some edge case bit observableproperty which is a big part of the library.

    So, what is actually supported? and I strongly believe 100% of all apps are using observableproperty so they all aren’t supported?

    • Sunil Joshi

      You can use the source generators instead of Observable which are AOT compatible.
      The reflection based apis obviously aren’t – and now they have the appropriate warnings to tell you.

      • Lukas Fellechner

        The sample does use the source generator to generate the observable property! That’s what the ObservableProperty attribute does. So it still looks like one of the most used features does not support NativeAOT? Or is it only when using ObservableProperty together with ObservableValidator?

        It would be great if you guys could show which features do support NativeAOT and which don’t (and what you can possibly do to get it still working).