问题描述
我无法将序列化对象从一个程序传递到另一个程序。
这两个程序在同一个解决方案中编译,并在同一台计算机上运行。对象源位于同一解决方案的共享文件夹中。
程序A序列化对象并将其写入命名管道。
程序B从中读取序列化对象命名管道并尝试将反序列化对象分配给相同的对象类型。
我收到以下错误:
[A] FileFind.FileFind.Shared.cs.CMUtilitySchedule不能转换为[B] FileFind.FileFind.Shared.cs.CMUtilitySchedule。
类型A源自'FileFind,Version = 5.0.0.6,Culture = neutral,PublicKeyToken = null'在上下文'Default'的位置'I:\ RodgerFolders \Documents\Visual Studio 2013\Projects\Test\FileFind\FileFind6000\FileFind\FileFind\bin\Debug\FileFind.exe。
类型B源自'FileFindCM,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'在上下文'Default'位置'I:\ RodgerFolders \Documents\Visual Studio 2013 \Projects\Test \FileFind \FileFind6000 \FileFind \FileFind \bin\Debug \FileFindCM.exe'。
怎么能我通过管道将对象传递给另一个正在运行的程序?
我尝试过:
我正在考虑在将创建CVS或XML流的对象中创建一个函数。然后我会序列化生成的流并将其发送到其他程序。然而,这将是一个非直观的维护噩梦。
欢迎其他建议。
I am having trouble passing a serialized object from one program to another.
The two programs are compiled in the same solution and are running on the same computer. The object source is in a shared folder in the same solution.
Program A serializes the object and writes it to a named pipe.
Program B reads the serialized object from the named pipe and attempts to assign the de-serialized object to the same object type.
I receive the following error:
[A]FileFind.FileFind.Shared.cs.CMUtilitySchedule cannot be cast to [B]FileFind.FileFind.Shared.cs.CMUtilitySchedule.
Type A originates from 'FileFind, Version=5.0.0.6, Culture=neutral, PublicKeyToken=null' in the context 'Default' at location 'I:\RogerFolders\Documents\Visual Studio 2013\Projects\Test\FileFind\FileFind6000\FileFind\FileFind\bin\Debug\FileFind.exe'.
Type B originates from 'FileFindCM, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' at location 'I:\RogerFolders\Documents\Visual Studio 2013\Projects\Test\FileFind\FileFind6000\FileFind\FileFind\bin\Debug\FileFindCM.exe'.
How can I pass objects to another running program via a pipe?
What I have tried:
I am thinking of creating a function in the object that will create a CVS or XML stream. I would then serialize the resulting stream and send it to the other program. However, that would be a non-intuitive maintenance nightmare.
Other suggestions would be welcome.
推荐答案
// project for A.exe
namspace A {
public class FileFind {
// ...
}
class A {
public static void Main(string[] args) {
// using FileFind...
}
}
}
// project for B.exe
namspace B {
public class FileFind {
// ...
}
class B {
public static void Main(string[] args) {
// using FileFind...
}
}
}
在这种情况下有两种不同类型甚至FileFind在项目A和B中具有完全相同的代码...
要解决它,你必须将FileFind移动到第三个项目并从A和B引用它
In this case there are two different types even FileFind has the exact same code in project A and B...
To resolve it you have to move FileFind to a third project and reference it both from A and B
// project for F.dll
namspace F {
public class FileFind {
// ...
}
}
// project for A.exe
using F;
namspace A {
class A {
public static void Main(string[] args) {
// using F.FileFind...
}
}
}
// project for B.exe
using F;
namspace B {
class B {
public static void Main(string[] args) {
// using F.FileFind...
}
}
}
这篇关于如何将对象传递给另一个程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!