AD RMS托管代码错误系统找不到指定的文件.HRESULT:0x80070002



我是Active Directory Rights Management Services(AD RMS)的新手,正在开发一个使用AD RMS加密某些文档的应用程序。我使用的是interop示例,但我得到了错误-系统找不到指定的文件。HRESULT:0x80070002-当我尝试运行以下代码时:

当我尝试运行以下语句时出错:

集合ipcTemplates=IPC.GetTemplates();

internal static class IPC
{
     static IPC()
     {
          SafeNativeMethods.IpcInitialize();
     }
     public static Collection<TemplateInfo> GetTemplates()
     {
          Collection<TemplateInfo> templates = null;
          try
          {
               templates = SafeNativeMethods.IpcGetTemplateList(null, true, true,
                                false, false, null, null);
          }
          catch (Exception /*ex*/)
          {
              /* TODO: Add logging */
              throw; 
          }
          return templates;
     }
}

堆栈跟踪:

系统找不到指定的文件。HRESULT:0x80070002在c:\Microsoft.InformationProtectionAndControl\SafeNativeMethods.ThrowOnErrorCode(Int32 hrError)中的c:\Microsoft.Information_ProtectionAndControl\SecurityNativeMethods:line 1678在c:\Microsoft.InformationProtectionAndControl\SafeNativeMethods.IpcGetTemplateList中(ConnectionInfo ConnectionInfo、Boolean forceDownload、Boolean suppressUI、Boolean offline、Boolean hasUserConsent、Form parentForm、CultureInfo CultureInfo)位于c:\IPC.cs 中的IPC.GetTemplates()

此外,我还设置了一个构建后事件,以确保每次编译代码时都会创建清单文件。该应用程序是托管在windows服务中的WCF服务。我有一个非常简单的控制台应用程序。

如果您能帮助解决此错误以及使用托管代码的任何AD RMS示例,我们将不胜感激:)

对于其他可能遇到此问题的人,我可以通过添加SafeNativeMethods.IpcSetAPIMode(APIMode.Server)来解决我的问题;我的静态构造函数是这样的:

static IPC()
    {
        SafeNativeMethods.IpcInitialize();
        SafeNativeMethods.IpcSetAPIMode(APIMode.Server);
    }

相关内容

最新更新