diff --git a/src/WinRT.Runtime/Projections/ICommand.net5.cs b/src/WinRT.Runtime/Projections/ICommand.net5.cs index 9edab7379..23cf930d3 100644 --- a/src/WinRT.Runtime/Projections/ICommand.net5.cs +++ b/src/WinRT.Runtime/Projections/ICommand.net5.cs @@ -252,7 +252,7 @@ private static unsafe int Do_Abi_remove_CanExecuteChanged_1(IntPtr thisPtr, glob try { var __this = global::WinRT.ComWrappersSupport.FindObject(thisPtr); - if (_CanExecuteChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler)) + if (__this != null && _CanExecuteChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler)) { __this.CanExecuteChanged -= __handler; } diff --git a/src/WinRT.Runtime/Projections/ICommand.netstandard2.0.cs b/src/WinRT.Runtime/Projections/ICommand.netstandard2.0.cs index db0319c66..6cf252457 100644 --- a/src/WinRT.Runtime/Projections/ICommand.netstandard2.0.cs +++ b/src/WinRT.Runtime/Projections/ICommand.netstandard2.0.cs @@ -237,7 +237,7 @@ private static unsafe int Do_Abi_remove_CanExecuteChanged_1(IntPtr thisPtr, glob try { var __this = global::WinRT.ComWrappersSupport.FindObject(thisPtr); - if (_CanExecuteChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler)) + if (__this != null && _CanExecuteChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler)) { __this.CanExecuteChanged -= __handler; } diff --git a/src/WinRT.Runtime/Projections/INotifyCollectionChanged.net5.cs b/src/WinRT.Runtime/Projections/INotifyCollectionChanged.net5.cs index 2e15f99b8..e5f656b5b 100644 --- a/src/WinRT.Runtime/Projections/INotifyCollectionChanged.net5.cs +++ b/src/WinRT.Runtime/Projections/INotifyCollectionChanged.net5.cs @@ -67,7 +67,7 @@ private static unsafe int Do_Abi_remove_CollectionChanged_1(IntPtr thisPtr, glob try { var __this = global::WinRT.ComWrappersSupport.FindObject(thisPtr); - if (_CollectionChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler)) + if (__this != null && _CollectionChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler)) { __this.CollectionChanged -= __handler; } diff --git a/src/WinRT.Runtime/Projections/INotifyCollectionChanged.netstandard2.0.cs b/src/WinRT.Runtime/Projections/INotifyCollectionChanged.netstandard2.0.cs index 29f3c2cf1..e83d6ddc8 100644 --- a/src/WinRT.Runtime/Projections/INotifyCollectionChanged.netstandard2.0.cs +++ b/src/WinRT.Runtime/Projections/INotifyCollectionChanged.netstandard2.0.cs @@ -74,7 +74,7 @@ private static unsafe int Do_Abi_remove_CollectionChanged_1(IntPtr thisPtr, glob try { var __this = global::WinRT.ComWrappersSupport.FindObject(thisPtr); - if (_CollectionChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler)) + if (__this != null && _CollectionChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler)) { __this.CollectionChanged -= __handler; } diff --git a/src/WinRT.Runtime/Projections/INotifyDataErrorInfo.net5.cs b/src/WinRT.Runtime/Projections/INotifyDataErrorInfo.net5.cs index ea47e5f39..b580daed4 100644 --- a/src/WinRT.Runtime/Projections/INotifyDataErrorInfo.net5.cs +++ b/src/WinRT.Runtime/Projections/INotifyDataErrorInfo.net5.cs @@ -108,7 +108,7 @@ private static unsafe int Do_Abi_remove_ErrorsChanged_2(IntPtr thisPtr, global:: try { var __this = global::WinRT.ComWrappersSupport.FindObject(thisPtr); - if (_ErrorsChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler)) + if (__this != null && _ErrorsChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler)) { __this.ErrorsChanged -= __handler; } diff --git a/src/WinRT.Runtime/Projections/INotifyDataErrorInfo.netstandard2.0.cs b/src/WinRT.Runtime/Projections/INotifyDataErrorInfo.netstandard2.0.cs index 1960cde5e..3e3e65aa5 100644 --- a/src/WinRT.Runtime/Projections/INotifyDataErrorInfo.netstandard2.0.cs +++ b/src/WinRT.Runtime/Projections/INotifyDataErrorInfo.netstandard2.0.cs @@ -134,7 +134,7 @@ private static unsafe int Do_Abi_remove_ErrorsChanged_2(IntPtr thisPtr, global:: try { var __this = global::WinRT.ComWrappersSupport.FindObject(thisPtr); - if (_ErrorsChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler)) + if (__this != null && _ErrorsChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler)) { __this.ErrorsChanged -= __handler; } diff --git a/src/WinRT.Runtime/Projections/INotifyPropertyChanged.net5.cs b/src/WinRT.Runtime/Projections/INotifyPropertyChanged.net5.cs index e7ef49c25..b4cc8313a 100644 --- a/src/WinRT.Runtime/Projections/INotifyPropertyChanged.net5.cs +++ b/src/WinRT.Runtime/Projections/INotifyPropertyChanged.net5.cs @@ -66,7 +66,7 @@ private static unsafe int Do_Abi_remove_PropertyChanged_1(IntPtr thisPtr, global try { var __this = global::WinRT.ComWrappersSupport.FindObject(thisPtr); - if (_PropertyChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler)) + if (__this != null && _PropertyChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler)) { __this.PropertyChanged -= __handler; } diff --git a/src/WinRT.Runtime/Projections/INotifyPropertyChanged.netstandard2.0.cs b/src/WinRT.Runtime/Projections/INotifyPropertyChanged.netstandard2.0.cs index 68da3dca9..54fdf2c9d 100644 --- a/src/WinRT.Runtime/Projections/INotifyPropertyChanged.netstandard2.0.cs +++ b/src/WinRT.Runtime/Projections/INotifyPropertyChanged.netstandard2.0.cs @@ -74,7 +74,7 @@ private static unsafe int Do_Abi_remove_PropertyChanged_1(IntPtr thisPtr, global try { var __this = global::WinRT.ComWrappersSupport.FindObject(thisPtr); - if (_PropertyChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler)) + if (__this != null && _PropertyChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler)) { __this.PropertyChanged -= __handler; } diff --git a/src/cswinrt/code_writers.h b/src/cswinrt/code_writers.h index a0461f258..8344b6598 100644 --- a/src/cswinrt/code_writers.h +++ b/src/cswinrt/code_writers.h @@ -4428,7 +4428,7 @@ private static unsafe int Do_Abi_%% try { var __this = global::WinRT.ComWrappersSupport.FindObject<%>(thisPtr); -if(_%_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(%, out var __handler)) +if(__this != null && _%_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(%, out var __handler)) { __this.% -= __handler; }