Windows 10 中的 CoCreateInstance 错误 0x80131700:无法使用 .NET 运行时 4.0 [英] CoCreateInstance error 0x80131700 in Windows 10: unable to work with .NET runtime 4.0

查看:40
本文介绍了Windows 10 中的 CoCreateInstance 错误 0x80131700:无法使用 .NET 运行时 4.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 Windows 10 企业版 20H2 Build 19042.1052 中运行的旧版 32 位应用程序,操作系统中预装了 .NET Framework 4.8 高级系列并处于活动状态.

I have a legacy 32 bit application running in Windows 10 Enterprise version 20H2 Build 19042.1052 with .NET Framework 4.8 Advanced Series pre-installed in the operating system and active.

遗留应用程序通过以下 C++ 代码作为 COM 对象加载一个用 C# 编写并使用目标框架 .NET 2.0 为 x86 构建的 .NET 程序集:

The legacy application loads a .NET assembly written in C# and built for x86 with target framework .NET 2.0 through the following C++ code as a COM object:

    #import "myassembly.tlb" no_namespace, raw_interfaces_only

    IMyClass *pMyClass = nullptr;

...

    HRESULT hr;
    CLSID clsid;

    // Load myassembly.dll as a COM object
    CoInitializeEx(nullptr, COINIT_MULTITHREADED);
    CLSIDFromString(OLESTR("{c0dc113c-3839-4427-8da5-35d768aff3d6}"), &clsid);          // This is the uuid of MyClass in myassembly.tlh
    hr = CoCreateInstance(clsid, nullptr, CLSCTX_INPROC_SERVER, __uuidof(IMyClass), reinterpret_cast<LPVOID *>(&pMyClass));
    if (FAILED(hr) || pMyClass == nullptr)
    {
        cout << "Cannot create COM Object\n";
        cout << "CoCreateInstance" << " hr = 0x" << std::hex << hr << " - ";
        std::wcout << getErrMsg(hr);
        CoUninitialize();
        return 1;
    }

我不想在 Windows 10 上安装 .NET framework 3.5,所以我为 .NET 程序集及其所有 .NET 依赖项添加了一个 .config 文件,如下所示:

I don't want to install the .NET framework 3.5 on Windows 10, so I added a .config file for the .NET assembly and for all its .NET dependencies like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0"/>
  <supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>

我尝试使用或不使用 useLegacyV2RuntimeActivationPolicy=true" 选项,但总是收到错误 0x80131700(未知错误")并弹出一个窗口,要求开始安装 .NET框架 3.5,我不想做,如上所述.事实上,如果我安装它,一切正常.

I tried with or without the useLegacyV2RuntimeActivationPolicy="true" option, but invariably I get an error 0x80131700 ("Unknown error") and a window pops up asking to start installation of .NET Framework 3.5, which I don't want to do, as said. Indeed, if I install it, everything is working fine.

有什么提示吗?

推荐答案

正如@Simon Mourier 在评论中指出的那样,问题是我需要添加一个 .config 文件,就像问题中的可执行文件 (myexe.exe.config) 而不是 .NET 程序集 (myassembly.dll.config).后一个其实没用.

As pointed out in the comments by @Simon Mourier, the problem was I needed to add a .config file like the one in the question for the executable (myexe.exe.config) rather than for the .NET assembly (myassembly.dll.config). The latter one is actually useless.

这篇关于Windows 10 中的 CoCreateInstance 错误 0x80131700:无法使用 .NET 运行时 4.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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