我发现了一个与构建使用 C:WindowsSystem32CertEnroll.dll 作为参考的应用程序相关的问题.
I have identified an issue related to building apps that use C:WindowsSystem32CertEnroll.dll as a reference.
以下代码在 Windows 7 上使用 VS 2015 编译然后在 Windows 7 机器上运行时运行良好.
The following code works fine when compiled using VS 2015 on Windows 7 and then ran on a Windows 7 machine.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CERTENROLLLib;
namespace CertTest
{
class Program
{
static void Main(string[] args)
{
try
{
CX509PrivateKey key = new CX509PrivateKey();
key.ContainerName = Guid.NewGuid().ToString();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
当您尝试在 Windows 10 中编译它,然后尝试在 Windows 7 机器上运行它时,它会引发以下错误.
When you try and compile this in Windows 10 and then try and run it on a Windows 7 machine, it throws the following error.
无法将类型为System.__ComObject"的 COM 对象转换为接口类型CERTENROLLLib.CX509PrivateKey".此操作失败,因为对具有 IID 的接口的 COM 组件调用 QueryInterface '{728AB362-217D-11DA-B2A4-000E7BBB2B09}' 由于以下错误而失败:不支持此类接口(来自 HRESULT 的异常:0x80004002 (E_NOINTERFACE))."
"Unable to cast COM object of type 'System.__ComObject' to interface type 'CERTENROLLLib.CX509PrivateKey'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{728AB362-217D-11DA-B2A4-000E7BBB2B09}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."
我有几个人在这里复制它,我想在联系 Microsoft 了解这里发生的事情之前获得更多信息.
I have had several people here replicate it and I'd like to get more input before contacting Microsoft on what's going on here.
我想我的问题是:其他人能否证实这一点,或者如果证实他们破坏了向后兼容性?
I guess my question is: Can anybody else confirm this or if it's confirmed they broke backward compatibilty?
这些是 Microsoft 解决此问题的步骤
These are the steps from Microsoft to resolve this issue
如果您仅使用 Windows 10 作为构建环境,那么可执行文件将在低级操作系统上运行,但是如果您真的只想拥有一个可以在任何地方编译并在任何地方运行的项目,那么唯一的解决方案就是创建自己的互操作包含在项目文件夹中的 DLL.您必须首先在 Windows 7 上生成它并引用该 DLL.
If you use Windows 10 solely as your build environment then the executable would run on downlevel OSes, however if you really just want to have a project that you can compile anywhere and run anywhere then the only solution is to create your own interop DLL that you include in the project folder. You would have to generate it on Windows 7 first and reference that DLL.
Tlbimp.exe CertEnroll_Interop c:WindowsSystem32CertEnroll.dll
Tlbimp.exe CertEnroll_Interop c:WindowsSystem32CertEnroll.dll
这会生成一个 CertEnroll_Interop.dll 文件,您可以将其复制到您的项目文件夹,然后在您的项目中浏览.当然,您需要使用使用 CertEnroll_Interop;"声明.
This generates a CertEnroll_Interop.dll file that you can copy to your project folder and then browse to in your project. Of course you would need the using "using CertEnroll_Interop;" statement.
您可以在 Windows 10 上构建项目并让它在 Windows 7 和 Windows 8.1 以及任何其他组合上运行.
You can build the project on Windows 10 and have it run on Windows 7 and Windows 8.1 and any other combination.
这篇关于在 Windows 10 中编译的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!