I started getting the exception below after starting to use a class from an open source MVVM framework that uses weak references to prevent memory leaks.
This class is called PropertyObserver
and is "A standardized way to handle the INotifyPropertyChanged.PropertyChanged
event of other objects. This class uses weak references and the weak-event pattern to prevent memory leaks."
The trigger for the exception was quitting a WPF app, in which a ShellVm
has a reference to a MasterVm
which has references to multiple DetailVm
s, each of which holds the aforementioned PropertyObserver
. The MasterVm
is ultimately the consumer of the static Inflector
class used to pluralize and capitalize this and that, which is where the WeakReference
related exception gets thrown.
I can't say I fully understand the exception, so I guess that is the starting point. How would I start to resolve this?
System.InvalidOperationException was unhandled by user code Message=Handle is not initialized. Source=mscorlib StackTrace: at System.WeakReference.set_Target(Object value) at System.Text.RegularExpressions.Regex.Replace(String input, String replacement, Int32 count, Int32 startat) at System.Text.RegularExpressions.Regex.Replace(String input, String replacement) at Inflector.Inflector.Rule.Apply(String word) at Inflector.Inflector.ApplyRules(List`1 rules, String word) at Inflector.Inflector.Pluralize(String word) at Smack.Core.Lib.TextUtil.StringEx.Pluralize(String s) at Smack.Core.Lib.TextUtil.StringEx.PluralizeWithCount[T](String s, IEnumerable`1 collection) at Smack.Core.Presentation.Wpf.ViewModels.MasterDetailVms.GenericMasterViewModel`2.get_Status() InnerException: