5
votes

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?

2
If I were you I would separate building from registration. They should not be mixed. For registration you need elevation. For building you do not. Build the project in the normal way, as standard user. Then elevate just to register.David Heffernan
Sorry, probably I mixed up the concepts, this is still very new to me. But to build I need a registration, right? So how do I elevate myself to register the Dll, so I can later build it?dialex
Not at all. You can build the software without any registration. The registration is what lets other programs find your COM object at runtime. Build in one step. Register in another. They are not related.David Heffernan
Were you ever able to resolve this? I have the exact same (very frustrating) issue.TwinPrimesAreEz
Sorry I don't recall how I solved this a year ago :(dialex

2 Answers

6
votes

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

1
votes

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.