dialex
dialex

Reputation: 2876

"Access to the Registry Key Denied" when building a .NET DLL for COM Interop

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:

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?

Upvotes: 11

Views: 12416

Answers (4)

Shrike
Shrike

Reputation: 66

I solved this Issue by decoupling the Registration and the Building-Process.

  1. Register the *.dll with regasm with Admin rights in CMD C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm NAME.dll /codebase for 32x programs

    C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm NAME.dll /codebase for 64x programs

  2. Run VisualStudio as Admin and build/run the program once

  3. Run VisualStudio as normal user and deactivate Register for COM interop (because we did this manually as Admin) Project -> Properties -> Building -> Register for COM interop

  4. Build / Run the project as normal user (should work now without problems)

Changes in your code should not influence the registration of the DLL, so you should be able to change things without having to re-register with Admin rights.

Register for COM interop

Upvotes: 0

philu
philu

Reputation: 874

Pass "/p:RegisterForComInterop=false" to MSBuild using the MSBuild Arguments process parameter of your build definition, assuming that your build server does not need to register the COM component but just build it.

Upvotes: 1

Robert J
Robert J

Reputation: 31

I got the same issue and I was able to resolve it opening the Registry Editor, go to the key that the error mentions. Right click and select "permissions...". I made sure that all users for my computer (since it is work computer) had full permissions. Save and now it works with no errors.

Upvotes: 3

crookie
crookie

Reputation: 270

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).

Upvotes: 8

Related Questions