Accessing registry through a dll project - error The type name 'RegistryKey' could not be found in the namespace 'Microsoft.Win32'

Jansen Barbara 6 Reputation points
2020-11-30T13:39:38.85+00:00

Dear all,

When trying to call Registry.CurrentUser.OpenSubKey I am having The type name 'RegistryKey' could not be found in the namespace 'Microsoft.Win32'. This type has been forwarded to assembly 'Microsoft.Win32.Registry, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.

even if including "using Microsoft.Win32;".

Same code works within program.cs

Any reason for this please and how I can resolve

Thanks

Developer technologies C#
{count} vote

1 answer

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2020-11-30T15:20:31.32+00:00

    The RegistryKey type is defined in the assembly Microsoft.Win32.Registry. You are referencing it from an older assembly that is forwarding to the newer assembly but that assembly isn't included. Add a reference to the Microsoft.Win32.Registry assembly and your problem should go away.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.