簡體   English   中英

為 COM 互操作構建 .NET DLL 時“拒絕訪問注冊表項”

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

目標:構建一個帶有 COM 互操作的 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 的步驟:“Access to the Registry Key Denied” Error Message When You Register .NET Assembly for COM Interop ,即定位和更改HKEY_CLASSES_ROOT\Component Categories\{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29} . 沒運氣。

如何獲得構建 DLL 和獲取tlb文件所需的權限?

我也有同樣的問題。 我也沒有設法解決您在問題中提供的鏈接。 但是,我確實有解決方法。 如果您以管理員身份打開 Visual Studio,那么一切正常(至少對我而言)。

我遇到了同樣的問題,我能夠打開注冊表編輯器解決它,轉到錯誤提到的鍵。 右鍵單擊並選擇“權限...”。 我確保我的計算機的所有用戶(因為它是工作計算機)都具有完全權限。 保存,現在它可以正常工作了。

使用構建定義的 MSBuild Arguments 過程參數將“/p:RegisterForComInterop=false”傳遞給 MSBuild,假設您的構建服務器不需要注冊 COM 組件而只需構建它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM