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

Fix app domain unloading issue on .NET Framework #4386

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ private Gen2GcCallback(Action<object> callback, object target)
/// <param name="target">The target object to pass as argument to <paramref name="callback"/>.</param>
public static void Register(Action<object> callback, object target)
{
#if NETSTANDARD2_0
if (RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework"))
{
// On .NET Framework using a GC callback causes issues with app domain unloading,
// so the callback is not registered if that runtime is detected and just ignored.
// Users on .NET Framework will have to manually trim the messenger, if they'd like.
return;
}
#endif

_ = new Gen2GcCallback(callback, target);
}

Expand Down
1 change: 1 addition & 0 deletions Microsoft.Toolkit.Mvvm/Messaging/WeakReferenceMessenger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace Microsoft.Toolkit.Mvvm.Messaging
/// The <see cref="WeakReferenceMessenger"/> type will automatically perform internal trimming when
/// full GC collections are invoked, so calling <see cref="Cleanup"/> manually is not necessary to
/// ensure that on average the internal data structures are as trimmed and compact as possible.
/// Note: this is not supported when running on .NET Framework, due to app domain unloading issues.
/// </para>
/// </remarks>
public sealed class WeakReferenceMessenger : IMessenger
Expand Down