0

My C# UWP project is x64 and it is part of packaging project. I add to my project links CertEnroll.dll and certcli.dll from Windows\SysWow64. Then I add code to create objects from CERTENROLLLib namespace.

using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using CERTCLILib;
using CERTENROLLLib;
...
CCspInformation cspInformation = new CCspInformationClass();
cspInformation.InitializeFromName(CngProvider.MicrosoftSoftwareKeyStorageProvider.Provider);

And compiler return error CS1752 “Interop type ‘CCspInformationClass’ cannot be embedded use the applicable interface instead”. After searching how fix this trouble, I found solution: set in project file EmbedInteropTypes attribute to false:

<COMReference Include="CERTENROLLLib">
    <Guid>{728AB348-217D-11DA-B2A4-000E7BBB2B09}</Guid>
    <VersionMajor>1</VersionMajor>
    <VersionMinor>0</VersionMinor>
    <Lcid>0</Lcid>
    <WrapperTool>tlbimp</WrapperTool>
    <Isolated>False</Isolated>
    <EmbedInteropTypes>False</EmbedInteropTypes>
</COMReference>

In this case project was built successfully, but debugging throws exception: Could not load file or assembly 'Interop.CERTENROLLLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. Then I try remove CertEnroll.dll from my project references and add Interop.CERTENROLLLib.dll. I also set in project file EmbedInteropTypes attribute to false:

<ItemGroup>
   <Reference Include="Interop.CERTENROLLLib">
      <HintPath>.\Interop.CERTENROLLLib.dll</HintPath>
      <EmbedInteropTypes>False</EmbedInteropTypes>
   </Reference>
</ItemGroup>

In this case debugger throws exception at the point of creating instance of CERTENROLLLib.CCspInformationClass:

COMException: Creating an instance of the COM component with CLSID {884E2007-217D-11DA-B2A4-000E7BBB2B09} using CoCreateInstanceFromApp failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). Please make sure your COM object is in the allowed list of CoCreateInstanceFromApp.

CERTENROLLLib types is not present in the registry. So, I try to register CertEnroll.dll and Interop.CERTENROLLLib.dll using

  • regsvr32 – raise error ‘Entry point is not found’
  • regasm – error RA0000 : Failed to load 'CertEnroll.dll' ('Interop.CERTENROLLLib.dll') because it is not a valid .NET assembly Finally, I try to change my project target platform to x86, but in this case the project is crushed. In the .Net project CertEnroll work fine. Is it possible in UWP?

My project properties:

My project properties

Build configuration:

Build configuration

My project references:

My project references

Stanislav
  • 33
  • 1
  • 5
  • You used CertEnroll.dll from SysWow64 (which is 32-bit subsystem) and project targets x64 platform. You should create interop library from %windir%\System32\certenroll.dll – Crypt32 Oct 05 '22 at 06:40
  • I repair my project after crush and change build configuration: set target platform x86 for UWP project and packaging project. Then I add reference to %windir%\System32\certenroll.dll and set EmbedInteropTypes to false (in *.csproj). As result, project is built successfully, but debugging throws FileNotFoundException: "Could not load file or assembly 'Interop.CERTENROLLLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified". I place Interop.CERTENROLLLib.dll in the project folder and add this path to reference paths. But exception is still thrown – Stanislav Oct 06 '22 at 16:56
  • why do we need Interop.CERTENROLLLib.dll? I some how ended up having it in my projects and wanted to remove it. – kudlatiger Jan 04 '23 at 10:31
  • @kudlatiger Interop.CERTENROLLLib.dll is CertEnroll Type Library. – Stanislav Jan 04 '23 at 22:40
  • Okay, does it have any impact if I remove it? I do not see we are calling any methods from it. – kudlatiger Jan 07 '23 at 07:09
  • @kudlatiger If you don't want to use this typelib, you may define it in the internal static class, using DllImport attribute for external functions. – Stanislav Jan 07 '23 at 20:51

0 Answers0