Tim*_*ter 5 .net remoting appdomain
我有一个.NET应用程序,其中单独的AppDomains中的程序集必须共享按值传递的序列化对象.
两个程序集都引用一个共享程序集,该程序集定义服务器类的基类,并定义将在域之间传递的entiy类型的基类:
public abstract class ServerBase : MarshalByRefObject
{
public abstract EntityBase GetEntity();
}
[Serializable]
public abstract class EntityBase
{
}
Run Code Online (Sandbox Code Playgroud)
服务器程序集定义服务器类和实体类型的具体实现:
public class Server : ServerBase
{
public override EntityBase GetEntity()
{
return new EntityItem();
}
}
[Serializable]
public class EntityItem : EntityBase
{
}
Run Code Online (Sandbox Code Playgroud)
客户端程序集创建AppDomain托管服务器程序集的位置,并使用服务器类的实例来请求实体类型的具体实例:
class Program
{
static void Main()
{
var domain = AppDomain.CreateDomain("Server");
var server = (ServerBase)Activator.CreateInstanceFrom(
domain,
@"..\..\..\Server\bin\Debug\Server.dll",
"Server.Server").Unwrap();
var entity = server.GetEntity();
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这种方法失败了,SerializationException因为客户端程序集并不直接了解返回的具体类型.
我已经读过使用二进制序列化时.NET Remoting支持未知类型,但我不确定这是否适用于我的设置或如何配置它.
或者,是否有任何其他方法可以将未知的具体类型从服务器传递到客户端,因为客户端只需要通过其已知的基类接口访问它.
谢谢你的建议,
蒂姆
编辑:
根据Hans的要求,这里是异常消息和堆栈跟踪.
SerializationException
Type is not resolved for member 'Server.EntityItem,Server, Version=1.0.0.0,Culture=neutral, PublicKeyToken=null'.
at Interop.ServerBase.GetEntity()
at Client.Program.Main() in C:\Users\Tim\Visual Studio .Net\Solutions\MEF Testbed\Client\Program.cs:line 12
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1700 次 |
| 最近记录: |