C# – “Access to the Registry Key Denied” when building a .NET DLL for COM Interop

ccom-interopdelphidllvisual studio 2012

Objective: build a C# DLL with COM interop to be called by Delphi on another environment.

Problem: Windows is blocking my build, saying that I don't have privileges to edit the registry.

Context:

  • I'm using Windows 8, Visual Studio 2012, UAC is turned off.
  • I'm using RGiesecke's DllExport to annotate with [DllExport] the methods that I want to export as an Dll.
  • I'm using [ComVisible(true)] as suggested here.
  • My solution platform target is x86
  • I edited my solution's build propertires and checked Build > Output > Register for COM Interop
  • I edited by AssemblyInfo.cs and enabled [assembly: ComVisible(true)]
  • I signed my assembly with a strong name

If I run VS2012 not as an admin I get this error: Cannot register assembly 'absolute\path\to\NameOf.dll' access denied. Please make sure you're running the application as administrator. Access to the registry key 'HKEY_CLASSES_ROOT\NameOf.DllClass' is denied

Maybe I need to run Visual Studio as an Administrator. However if I run VS2012 as an admin I get this other error (even more random): Cannot register assembly. Could not load file or assembly 'RGiesecke.DllExport.Metadata, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ad5f9f4a55b5020b' or one of its dependencies. The system cannot find the file specified.

I followed the steps of FIX: "Access to the Registry Key Denied" Error Message When You Register .NET Assembly for COM Interop, namely locating and changing the permissions for HKEY_CLASSES_ROOT\Component Categories\{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}. No luck.

How can I get the privileges needed to build my DLL and get my tlb file?

Best Answer

I have the same problem. I also didn't manage to get a fix with the link you put in the question. I do however have a work-around. If you open Visual Studio as Administrator, then it all works (for me at least).