diff --git a/Microsoft.Toolkit.Mvvm/Messaging/Messenger.cs b/Microsoft.Toolkit.Mvvm/Messaging/Messenger.cs index f8e817e0..9c27badd 100644 --- a/Microsoft.Toolkit.Mvvm/Messaging/Messenger.cs +++ b/Microsoft.Toolkit.Mvvm/Messaging/Messenger.cs @@ -638,9 +638,14 @@ namespace Microsoft.Toolkit.Mvvm.Messaging [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Type2 other) { + // We can't just use reference equality, as that's technically not guaranteed + // to work and might fail in very rare cases (eg. with type forwarding between + // different assemblies). Instead, we can use the == operator to compare for + // equality, which still avoids the callvirt overhead of calling Type.Equals, + // and is also implemented as a JIT intrinsic on runtimes such as .NET Core. return - ReferenceEquals(this.tMessage, other.tMessage) && - ReferenceEquals(this.tToken, other.tToken); + this.tMessage == other.tMessage && + this.tToken == other.tToken; } ///