Windows 10中的编译问题 [英] Issues compiling in Windows 10

查看:75
本文介绍了Windows 10中的编译问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了与构建使用C:\ Windows \ System32 \ CertEnroll.dll作为参考的应用程序有关的问题.

I have identified an issue related to building apps that use C:\Windows\System32\CertEnroll.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为'{728AB362-217D-11DA-B2A4'的接口的COM组件上的QueryInterface调用-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:\ Windows \ System32 \ CertEnroll.dll

Tlbimp.exe CertEnroll_Interop c:\Windows\System32\CertEnroll.dll

这将生成一个CertEnroll_Interop.dll文件,您可以将其复制到项目文件夹中,然后在项目中浏览到.当然,您需要使用"using 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中的编译问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆