.NET客户端crasch更换COM注册.dll文件与新的相同的.NET版本的客户端客户端、版本、文件、NET

2023-09-03 16:10:57 作者:刀尖岁月柔

我们有一个旧的C / C ++的.dll是COM注册。我们的客户有使用此.dll既native-和.NET客户端。

我们已经建立了一个新的.NET .dll文件,以取代旧的,即它们的COM接口是相同的。我们希望,以取代旧的.dll没有我们的客户需要重新编译或做点儿给他们的客户。

设置自动清除内存中没用的DLL文件

有关本地客户端能正常工作简单地注销旧的.dll文件和注册新的(与regasm)。它也适用于一些.NET客户端。然而,在这些情况下,在客户机和新的.dll编译时它将引发下面的异常相同.NET版本。

在换句话说,这部作品:

  .DLL是.NET 3.5  - >客户端是.NET 4.0
.dll文件是.NET 4.0  - >客户端是.NET 3.5
.DLL任何.NET  - >客户端是原生
 

这将引发以下exeption:

  .DLL是.NET 4.0  - >客户端是.NET 4.0
.dll文件是.NET 3.5  - >客户端是.NET 3.5
 

  

[A] BARAPIXLib.barcom5不能转换为[B] BARAPIXLib.barcom5。

     

键入从A发出'BARAPIXLib,版本= 1.0.0.0,文化=中性公钥=空'的背景下,'LoadFrom'的位置C:\ ARKIV \ S_BTW \ BTW \ BARAPIXWebService \ Barapix \ BIN \ BARAPIXLib.dll

     \ ARKIV \ Bartrack \ BartrackTest \ 86 \ SRC \ BartrackTest \ BIN \:

B型从'BartrackTest,版本= 1.0.0.0,文化=中性公钥=空'的背景下,默认的位置'C起源86 \发布\ BartrackTest.exe'。}

任何想法,将AP preciated。

解决方案

这可能是因为在你使用.NET Framework的版本相同的情况下,该实例返回到客户端是不是不再是一个COM包装,但一纯.NET对象,所以当你尝试将其转换为失败COM接口。 有一个类似的问题here.该解决方案包括使用主Interop大会。

We have an old C/C++ .dll that is COM registered. Our customers have both native- and .NET clients that use this .dll.

We have built a new .NET .dll to replace the old one, i.e. their COM interface is identical. We would like to replace the old .dll without our customer need to recompile or do anyting to their clients.

For native clients it works fine to simply unregister the old .dll and register the new one (with regasm). It also works for some .NET clients. However, in those cases the both the client and the new .dll is compiled with the same .NET version it throws the exception below.

In other words, this works:

.dll is .NET 3.5 -> client is .NET 4.0
.dll is .NET 4.0 -> client is .NET 3.5
.dll is any .NET -> Client is native

This throws the exeption below:

.dll is .NET 4.0 -> client is .NET 4.0
.dll is .NET 3.5 -> client is .NET 3.5

[A]BARAPIXLib.barcom5 cannot be cast to [B]BARAPIXLib.barcom5.

Type A originates from 'BARAPIXLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadFrom' at location C:\arkiv\S_BTW\BTW\BARAPIXWebService\Barapix\bin\BARAPIXLib.dll'.

Type B originates from 'BartrackTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' at location 'C:\arkiv\Bartrack\BartrackTest\x86\Src\BartrackTest\bin\x86\Release\BartrackTest.exe'."}

Any ideas would be appreciated.

解决方案

This might be because in the case where you are using the same version of .net framework, the instance returned to the client is not longer a COM wrapper but a pure .Net object, so when you try to cast it to a COM interface it fails. There is a similar question here. The solution involves using Primary Interop Assembly.