Hello everybody,
On my previous machine, I had this to read a value in the registry:
When receiving a new machine, I got a "variable not implemented" exception, and I had to write this:
On the previous machine, if the key is absent, v receives the default value.
On the new one, it receives null, so parsing it to an integer raises an exception.
I needed a little time to understand what happened, at a moment I thought Registry had to be implemented, and it did not make sense.
I have a doubt about a comportment of the Registry object (and its GetValue method) that would be specific to a machine.
Were there any changes in .Net?
Oh, perhaps an element: the project was created targeting net5.0-windows
On the new machine, as this version of .Net was not installed, Visual studio proposed to migrate it to net6.0-windows, and I accepted.
On my previous machine, I had this to read a value in the registry:
Reading a value in the registry:
private bool getReg()
{
object v = Registry.GetValue(
@"HKEY_CURRENT_USER\Console\SonsTest",
"JouerSelectReminder",
4
);
string strSelectReminder = v.ToString();
double dwSelectReminder = double.Parse(strSelectReminder);
return dwSelectReminder == 1;
}
When receiving a new machine, I got a "variable not implemented" exception, and I had to write this:
Reading the registry, new version:
private bool getReg()
{
object v = Registry.GetValue(
@"HKEY_CURRENT_USER\Console\SonsTest",
"JouerSelectReminder",
4
);
if (v == null)
{
//key noot present in the register
return false;
}
else
{
string strSelectReminder = v.ToString();
double dwSelectReminder = double.Parse(strSelectReminder);
return dwSelectReminder == 1;
}
}
On the previous machine, if the key is absent, v receives the default value.
On the new one, it receives null, so parsing it to an integer raises an exception.
I needed a little time to understand what happened, at a moment I thought Registry had to be implemented, and it did not make sense.
I have a doubt about a comportment of the Registry object (and its GetValue method) that would be specific to a machine.
Were there any changes in .Net?
Oh, perhaps an element: the project was created targeting net5.0-windows
On the new machine, as this version of .Net was not installed, Visual studio proposed to migrate it to net6.0-windows, and I accepted.
Last edited: