tags:

views:

123

answers:

5
A: 

Is posible, the reflection was set the "isLoggedInLock" to the null? With FieldInfo.SetValue() you can change value of readonly field.

TcKs
+3  A: 

The most likely cause, from a 10 second look at the code, is OnPropertyChanged.

I am guessing from the naming that it raises an event. Can we see the code for this method? Chances are it is invoking the event handler without first doing a null check to check someone is subscribed.

[Edit - sorry didn't read that you'd identified isLoggedInLock as the culprit]

Are you sure it is isLoggedInLock - as there doesn't look like much scope for this being null. As it is marked as readonly, it can't possibly be being set to null in elsewhere in the method.

Is this an accurate representation of the affected code? Definitely not the case that the property is static, or some such difference?

Rob Levine
Sorry I left out a crucial part of it, see my edits.
Dabblernl
+2  A: 

Do you have a static constructor? (and does it use IsLoggedIn ?)

James Curran
+3  A: 

The only reason an ArgumentNullException can be thrown in the code you posted is if isLoggedInLock is null when you execute the lock statement. So unless you are explicitly setting isLoggedInLock to null elsewhere (and this can only be in the constructor since the field is readonly), your assumption is correct:

it seems that it has not been instantiated before the setter is called

Fields will be initialized in the order they are declared, so if you have a field initialization higher up that calls a member that accesses the IsLoggedIn property, this will happen before isLoggedInLock is initialized.

If you look at the stack trace from the exception it should be easy to work out what's going on.

Joe
A: 

It is possible that a field of a class is null, even when it is initialized in the constructor: when the class comes into life through deserialization, the constructor is not called....

Dabblernl