System.Windows.SystemParameters.PrimaryScreenWidth throws NullReferenceException sometimes

double width = SystemParameters.PrimaryScreenWidth;
double height = SystemParameters.PrimaryScreenHeight;

The above two lines throw NullReferenceException sometimes? Is there any better way to get screen resolution in WPF?

Edit: Just realize that these two properties are double and a double can never be null. But the stack trace points to these two lines.