I'm new to Active Directory Rights Management Services (AD RMS) and I'm developing an application to use AD RMS to encrypt some documents. I'm using the interop example and I get the error - The system cannot find the file specified. HRESULT: 0x80070002 - when I try to run the code below:
I get the error when I try to run this statement:
Collection 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;
}
}
Stack Trace:
The system cannot find the file specified. HRESULT: 0x80070002 at Microsoft.InformationProtectionAndControl.SafeNativeMethods.ThrowOnErrorCode(Int32 hrError) in c:\Microsoft.InformationProtectionAndControl\SafeNativeMethods.cs:line 1678 at Microsoft.InformationProtectionAndControl.SafeNativeMethods.IpcGetTemplateList(ConnectionInfo connectionInfo, Boolean forceDownload, Boolean suppressUI, Boolean offline, Boolean hasUserConsent, Form parentForm, CultureInfo cultureInfo) in c:\Microsoft.InformationProtectionAndControl\SafeNativeMethods.cs:line 137 at IPC.GetTemplates() in c:\IPC.cs
Also, I have set up a post build event to make sure the manifest file gets created every time the code is compiled. The application is a WCF service hosted in a windows service. I have a very simple console app that works.
Any help in resolving this error and any AD RMS examples using managed code would be appreciated :)
For anyone else that may run into this issue I was able to resolve my problem by adding SafeNativeMethods.IpcSetAPIMode(APIMode.Server); to my static constructor like this:
static IPC()
{
SafeNativeMethods.IpcInitialize();
SafeNativeMethods.IpcSetAPIMode(APIMode.Server);
}