File tree Expand file tree Collapse file tree 2 files changed +11
-0
lines changed
Expand file tree Collapse file tree 2 files changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,16 @@ private Gen2GcCallback(Action<object> callback, object target)
4141 /// <param name="target">The target object to pass as argument to <paramref name="callback"/>.</param>
4242 public static void Register ( Action < object > callback , object target )
4343 {
44+ #if NETSTANDARD2_0
45+ if ( RuntimeInformation . FrameworkDescription . StartsWith ( ".NET Framework" ) )
46+ {
47+ // On .NET Framework using a GC callback causes issues with app domain unloading,
48+ // so the callback is not registered if that runtime is detected and just ignored.
49+ // Users on .NET Framework will have to manually trim the messenger, if they'd like.
50+ return ;
51+ }
52+ #endif
53+
4454 _ = new Gen2GcCallback ( callback , target ) ;
4555 }
4656
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ namespace CommunityToolkit.Mvvm.Messaging
3030 /// The <see cref="WeakReferenceMessenger"/> type will automatically perform internal trimming when
3131 /// full GC collections are invoked, so calling <see cref="Cleanup"/> manually is not necessary to
3232 /// ensure that on average the internal data structures are as trimmed and compact as possible.
33+ /// Note: this is not supported when running on .NET Framework, due to app domain unloading issues.
3334 /// </para>
3435 /// </remarks>
3536 public sealed class WeakReferenceMessenger : IMessenger
You can’t perform that action at this time.
0 commit comments