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:
Build configuration:
My project references: