It's after a few days of unsuccessful research that I come back to you. I have a WPF application in dotnet 4.5, and the application settings stored as UserSettings, one parameter is of DateTime type (the expiry date of the token), and for each application launch I compare this parameter with DateTime.Now (to see if the token has expired or I can use it). That's works perfectly in Win 10 even in some Win7, because now i install it in another Win 7 machine, it generates NullReferenceException (for the DateTime Parameter : token_expire_time)
I wanted to do a method that returns a boolean, to see if this parameter was initialized (DateTime dt = new DateTime()) or not, but I can not find how to do it.
Thanks by advance.
public string get_token()
{
int result_time = DateTime.Compare(DateTime.Now, Properties.Settings.Default.token_expire_time); // NullReferenceException
// Check if token is not expired
if (result_time >= 0)
{
// Token expired
// so get another token
}
// return the token setting stored (string)
return Properties.Settings.Default.token;
}
My question is not a duplicate of What is a NullReferenceException, and how do I fix it?: 1-problem in C# not VisualBasic 2- Problem in Properties.Settings.settings not in declaration of variable in the code