远程序列化一个文件,服务端在本机时,可以正常,一到远端,就报错,找了很久,迷惑中啊?请大侠指教- __identity System.Runtime.Remoting.RemotingException: 远程处理无法在类型“System.MarshalByRefObject”上找到字段“__identity”。Server stack trace: 
   在 System.Object.GetFieldInfo(String typeName, String fieldName)
   在 System.Object.FieldGetter(String typeName, String fieldName, Object& val)
   在 System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
   在 System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
   在 System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)Exception rethrown at [0]: 
   在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   在 System.Object.FieldGetter(String typeName, String fieldName, Object& val)
   在 System.RuntimeFieldHandle.GetValue(Object instance, RuntimeTypeHandle fieldType, RuntimeTypeHandle declaringType, Boolean& domainInitialized)
   在 System.Reflection.RtFieldInfo.InternalGetValue(Object obj, Boolean doVisibilityCheck, Boolean doCheckConsistency)
   在 System.Reflection.RtFieldInfo.GetValue(Object obj)
   在 Microsoft.Office.Tools.Debugger.Tools.TryCreateDebuggerItem(MemberInfo member, Object target, __Item& item) System.Runtime.Remoting.RemotingException- Identity System.Reflection.TargetInvocationException: 调用的目标发生了异常。 ---> System.Runtime.Remoting.RemotingException: 权限被拒绝: 无法远程调用非公共或静态方法。Server stack trace: 
   在 System.Runtime.Remoting.Channels.ChannelServices.DispatchMessage(IServerChannelSinkStack sinkStack, IMessage msg, IMessage& replyMsg)Exception rethrown at [0]: 
   在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   在 System.MarshalByRefObject.get_Identity()
   --- 内部异常堆栈跟踪的结尾 ---
   在 System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   在 System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   在 System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   在 Microsoft.Office.Tools.Debugger.Tools.TryCreateDebuggerItem(MemberInfo member, Object target, __Item& item) System.Reflection.TargetInvocationException

解决方案 »

  1.   

    报错位置 
    IFile file = (IFile)Activator.GetObject(typeof(IFile), url);
      

  2.   

    使用MemoryStream,连接是否正确
    参考
      

  3.   

    Dim rss As RemotingSurrogateSelector = New RemotingSurrogateSelector()
    Dim obj As Object = rss.GetRootObject()
    Dim stream As MemoryStream = New MemoryStream()
    Dim formatter As BinaryFormatter = New BinaryFormatter()'序列化的时候要用RemotingSurrogateSelector formatter.SurrogateSelector = rss
    formatter.Serialize(stream, item)
    stream.Seek(0, SeekOrigin.Begin)'反序列化的时候不用RemotingSurrogateSelector 
    Dim formatter1 As BinaryFormatter = New BinaryFormatter()
    Dim result As T = CType(formatter1.Deserialize(stream), T)
    stream.Close()