32 位进程如何与 .NET 中的 64 位进程通信? [英] How can a 32 bit process communicate with a 64 bit process in .NET?

查看:39
本文介绍了32 位进程如何与 .NET 中的 64 位进程通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows 无法让 32 位进程加载 64 位 dll,因此我尝试使用远程处理以允许 32 位进程与 64 位进程交互.

问题是:虽然这两个应用程序位于同一台机器上,一个是 32 位的,另一个是 64 位的,而且它们必须是这样:同时使用 32 位或 64 位会破坏这些应用程序的一切建立在.

我正在使用 .NET 的 System.Runtime.Remoting.RemotingConfiguration 类并调用其 Configure() 方法并传递对 App.config 文件的引用,该文件引用了我将通过远程处理访问的 MarshalByRefObject 类.

我让它工作了,但前提是 Client、Host、MarshalByRefObject 类是 32 位或 64 位.如果我把它们混在一起,这将不起作用:我最终会得到一个 BadImageFormatException:

无法加载文件或程序集MyRemotingObject"或其依赖项之一.试图加载格式不正确的程序.

一旦我将两个应用程序都设为 32 位或 64 位,异常就会消失,但同样,其中一个必须是 32 位,另一个必须是 64 位.

谁能告诉我如何在 32 位 .NET 应用程序和 .64 位 .NET 应用程序之间启用进程间通信?

解决方案

随机猜测:.NET 远程处理需要将程序集加载到两个进程中以获取元数据.您的数据协定(使用 WCF 术语)应该在一个单独的程序集中,并且应该编译为AnyCPU",以便它可以加载到任一进程中.您已将其明确设置为 32 位或 64 位.

Windows does not make it possible for a 32 bit process to load a 64 bit dll, so I am trying to use remoting in order to allow the 32 bit process to interact with a 64 bit process.

Here's the problem: while the two applications are located on the same machine, one is 32 bit and the other is 64 bit, and they have to be that way: making both 32 bit or 64 bit would break everything these applications are built on top of.

I'm using .NET's System.Runtime.Remoting.RemotingConfiguration class and calling its Configure() method and passing a reference to an App.config file which references the MarshalByRefObject class that I'll be accessing via remoting.

I got it to work, but only as long Client, Host, MarshalByRefObject class are either 32 bit or 64 bit. If I mix them up this won't work: I'll end up with a BadImageFormatException:

Could not load file or assembly 'MyRemotingObject' or one of its dependencies. An attempt was made to load a program with an incorrect format.

The exception goes away as soon as I make both apps either 32 bit or 64 bit, but again, one of them must be 32 bit and the other 64 bit.

Can someone tell me how to enable interprocess communication between a 32 bit .NET app and a .64 bit .NET app?

解决方案

Random guess: .NET remoting needs to load the assembly into both processes to get hold of the metadata. Your data contract (to use the WCF term) should be in a separate assembly and should be compiled as "AnyCPU", so that it can be loaded into either process. You've got it explicitly set to 32-bit or 64-bit.

这篇关于32 位进程如何与 .NET 中的 64 位进程通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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