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

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=, 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


An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,180 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Michael Taylor 47,471 Reputation points

    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.