I have a property defined in an interface as:
Boolean IsBusy { get; }
It is implemented in the class as:
private Boolean _isBusy = false;
public Boolean IsBusy
{
get
{
return this._isBusy;
}
private set
{
if (this._isBusy != value)
{
this._isBusy = value;
this.OnPropertyChanged("IsBusy");
}
}
}
Then when I run the app, I always get following kind of error when check IsBusy value in constructor:
'IsBusy' threw an exception of type 'System.NullReferenceException' bool {System.NullReferenceException}
I can't figure it out. If I change all Boolean to bool, get same error.
How can I fix it?
You fix it by checking whether OnPropertyChanged is null before calling it, assuming OnPropertyChanged is an event or a delegate variable (you haven't made this clear). This has nothing to do with bool or Boolean, which are equivalent (assuming that Boolean is resolved to System.Boolean).
I can't see any other reason it would throw NullReferenceException - although it would really help you could clarify whether you were calling the getter or the setter at the time it threw the exception. A short but complete example would be even more helpful.
bool is just a syntax shortcut for Boolean
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With