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

C#
C#
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,648 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Michael Taylor 51,346 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.