尝试从本机应用程序并行访问 .NET 程序集时出现 OLE 错误 80131522

发布于 2024-09-30 07:40:41 字数 1600 浏览 4 评论 0原文

我有一个应用程序(Delphi 本机代码)需要访问 .NET 程序集(公开一些 COM 类)。我想使用并排程序集和清单来执行此操作。我已经使用测试 .NET 程序集完成了此操作,但是我我需要访问的程序集有问题。

注册程序集后,我可以实例化 COM 类,然后尝试并行访问,我的本机应用程序出现上述错误。 我的程序

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity type="win32"
                    name="TestApplication.exe"
                    version="1.0.0.0"/>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
        name="TestAssembly"
        version="1.0.0.0"
        processorArchitecture="x86"
        publicKeyToken="xxxxxxxxxxxxxxxx"
        type="win32"/>
    </dependentAssembly>
  </dependency>
</assembly>

集清单(我已将其作为资源嵌入到我的 .net 程序集中)如下:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity
    name="TestAssembly"
    version="1.0.0.0"
    processorArchitecture="x86"
    publicKeyToken="xxxxxxxxxxxxxxxx"
    type="win32"/>
  <clrClass
    clsid="{F3F1623D-DB4A-4152-9A5D-5A465AD3A318}"
    progid="TestAssembly.MyObject"
    threadingModel="Both"    
    name="TestAssembly.MyObject"
    runtimeVersion="v2.0.50727">
  </clrClass>
  <file name="TestAssembly.dll">
  </file>
</assembly>     

如果我更改应用程序清单的依赖项名称、版本,则清单似乎设置正确。或公钥令牌(顺便说一句,示例中的令牌不是我代码中的令牌),我收到有关应用程序配置不正确的常见 SxS 错误,

我在另一个(诚然更简单).NET 程序集上进行了此操作,但是。无法弄清楚出了什么问题。问题是我不确定该错误意味着什么。

I have an application (Delphi Native code) that needs to access a .NET assembly (exposes a few COM classes. I want to do this using side by side assemblies and manifests. I have done this with a test .NET assembly, but am having a problem with the assembly I need to access.

When the assembly is registered, I can instantiate the COM class. As soon as I unregister the assembly, and try to access side by side I get the above error. My native application has an application manifest, which has a simple dependency to the assembly.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity type="win32"
                    name="TestApplication.exe"
                    version="1.0.0.0"/>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
        name="TestAssembly"
        version="1.0.0.0"
        processorArchitecture="x86"
        publicKeyToken="xxxxxxxxxxxxxxxx"
        type="win32"/>
    </dependentAssembly>
  </dependency>
</assembly>

My Assembly manifest, which I have embedded as a resource into my .net assembly is the following :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity
    name="TestAssembly"
    version="1.0.0.0"
    processorArchitecture="x86"
    publicKeyToken="xxxxxxxxxxxxxxxx"
    type="win32"/>
  <clrClass
    clsid="{F3F1623D-DB4A-4152-9A5D-5A465AD3A318}"
    progid="TestAssembly.MyObject"
    threadingModel="Both"    
    name="TestAssembly.MyObject"
    runtimeVersion="v2.0.50727">
  </clrClass>
  <file name="TestAssembly.dll">
  </file>
</assembly>     

The manifests seems to be setup correctly. If I change the application manifest's dependency name, version or public key token (the one in the example is not the one i have in my code btw), I get the usual SxS error about the application configuration is incorrect.

I have this working on another (admittedly simpler) .NET assembly, but cannot figure out what is wrong. Problem is I'm not sure what the error means.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ˉ厌 2024-10-07 07:40:41

要生成 .Net 程序集清单,请像这样使用 mt.exe

c:>mt.exe -nologo -managedassemblyname:"your_binary.dll" -nodependency -out:"temp_file.manifest"
c:>mt.exe -nologo -manifest "temp_file.manifest" -outputresource:"your_binary.dll";2

然后打开 temp_file.manifest 并在您的 dependency\dependentAssembly 标记下逐字复制 assemblyIdentity 标记delphi 可执行文件清单。

仅供参考:您必须将可执行文件和所有依赖的 .net dll 保存在同一文件夹中。

To generate .Net assembly manifest use mt.exe like this

c:>mt.exe -nologo -managedassemblyname:"your_binary.dll" -nodependency -out:"temp_file.manifest"
c:>mt.exe -nologo -manifest "temp_file.manifest" -outputresource:"your_binary.dll";2

Then open temp_file.manifest and copy assemblyIdentity tag verbatim under dependency\dependentAssembly tag of your delphi executable manifest.

FYI: You have to keep both the executable and all dependent .net dlls in the same folder.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文