Search code examples
c#registry

Cannot implicitly convert type void to microsoft.win32.registrykey


Error: cannot implicitly convert type void to microsoft.win32.registrykey

Code:

using Microsft.Win32;
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Sofware",true).DeleteSubKey("TEST");

But for some reason this code works:

using Microsft.Win32;
RegistryKey key1 = Registry.CurrentUser.OpenSubKey(@"Sofware", true).CreateSubKey("TEST");

Solution

  • Looking at the signature of DeleteSubKey here It says it is void, hence it returns nothing and cannot be assigned to RegistryKey. Call the function without using its return value