Registry in .NET: DeleteSubKeyTree says the subkey does not exists, but hey, it does!
        Posted  
        
            by CharlesB
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by CharlesB
        
        
        
        Published on 2010-06-02T16:01:46Z
        Indexed on 
            2010/06/02
            16:03 UTC
        
        
        Read the original article
        Hit count: 566
        
Hi,
Trying to delete a subkey tree: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.hdr. .hdr subkey has one subkey, no values. So I use this code:
RegistryKey FileExts = Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts");
RegistryKey faulty = FileExts.OpenSubKey(".hdr");
Debug.Assert (faulty != null && faulty.SubKeyCount != 0);
faulty.Close();
FileExts.DeleteSubKeyTree(".hdr");
And I get the ArgumentException with message "Cannot delete a subkey tree because the subkey does not exist."
WTF? I checked and asserted it did exist?
© Stack Overflow or respective owner