为COM Interop构建.NET DLL时“访问注册表项被拒绝”

目标 : 使用COM interop构建一个C#DLL,由Delphi在另一个环境中调用 。

问题 :Windows阻止了我的构建,说我没有编辑注册表的权限。

语境:

  • 我正在使用Windows 8,Visual Studio 2012,UAC已关闭。
  • 我正在使用RGiesecke的DllExport来使用[DllExport]注释我想要导出为Dll的方法。
  • 我在这里建议使用[ComVisible(true)]
  • 我的解决方案平台目标是x86
  • 我编辑了我的解决方案的构建属性,并检查了Build > Output > Register for COM Interop
  • 我通过AssemblyInfo.cs编辑并启用[assembly: ComVisible(true)]
  • 我用一个强有力的名字签署了我的大会

如果我不是作为管理员运行VS2012我得到此错误: 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 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

也许我需要以管理员身份运行Visual Studio。 但是,如果我作为管理员运行VS2012,我会得到另一个错误(甚至更随机): 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. 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.

我按照FIX:“访问注册表项被拒绝”的步骤为COM Interop注册.NET程序集时出现错误信息 ,即查找和更改HKEY_CLASSES_ROOT\Component Categories\{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29} 。 没运气。

如何获得构建我的DLL并获取我的tlb文件所需的权限?

我也有同样的问题。 我也没有设法解决您在问题中提供的链接。 但是,我确实有一个解决方法。 如果以管理员身份打开Visual Studio,则一切正常(至少对我而言)。

我遇到了同样的问题,我能够解决它打开注册表编辑器,转到错误提到的密钥。 右键单击并选择“权限…”。 我确保我的计算机的所有用户(因为它是工作计算机)具有完全权限。 保存,现在它没有错误。