将.NET注册的.dll替换为与客户端相同的.NET版本的新客户端时,.NET客户端崩溃 [英] .NET Client crasch when replacing COM registered .dll with new one in same .NET version as client

查看:139
本文介绍了将.NET注册的.dll替换为与客户端相同的.NET版本的新客户端时,.NET客户端崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我们已经构建了一个新的.NET .dll来替换旧的.dll,即它们的COM接口是相同的。我们想替换旧的.dll,而不需要我们的客户需要重新编译或对客户进行任何操作。



对于本机客户端,简单地取消注册旧的.dll并注册新的。它也适用于某些.NET客户端。但是,在这些情况下,客户端和新的.dll都将使用相同的.NET版本进行编译,它会在下面引发异常。



换句话说,这样做:

  .dll是。 NET 3.5  - >客户端是.NET 4.0 
.dll是.NET 4.0 - >客户端是.NET 3.5
.dll是任何.NET - >客户是本地的

这将抛出以下内容:

  .dll是.NET 4.0  - >客户端是.NET 4.0 
.dll是.NET 3.5 - >客户端是.NET 3.5




[A] BARAPIXLib.barcom5无法投射到[B] BARAPIXLib.barcom5。



类型A起源于上下文LoadFrom中的'BARAPIXLib,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'在位置C:\arkiv\S_BTW\BTW\BARAPIXWebService\Barapix\bin\BARAPIXLib.dll'。



类型B源于'BartrackTest ,版本= 1.0.0.0,Culture = neutral,PublicKeyToken = null'在上下文'Default'位置'C:\arkiv\Bartrack\BartrackTest\x86\Src\BartrackTest\bin\x86 \Release\BartrackTest.exe'。}


任何想法都将不胜感激。

解决方案

这可能是因为在使用相同版本的.net框架的情况下,返回给客户端的实例不再是COM包装器,而是纯粹的.Net对象,所以当你尝试将其转换为COM接口失败
有一个类似的问题此处。该解决方案涉及使用主要Interop Assembly


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.

这篇关于将.NET注册的.dll替换为与客户端相同的.NET版本的新客户端时,.NET客户端崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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