The following method in my class library works fine when I call them from ConsoleApp. But when I try to unit test it, the registry value is not updated. Why?
I get a null-reference error.
namespace ClassLibrary1
{
public class Class1
{
public static void MyMethod()
{
string targketKey = @"SOFTWARE\MyApp1";
using (Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(targetKey, true))
{
rk.SetValue("target", "new value", Microsoft.Win32.RegistryValueKind.String);
}
}
}
}