实体类
[Serializable]
    public class User
    {
        public int id;
        public string name;
    }比如有一个Remoting对象的方法,string GetUserInfo(User user),调用该方法时,出现异常:System.Runtime.Serialization.SerializationException
  Message="由于安全限制,无法访问类型 Common.User。"
  Source="mscorlib"
  StackTrace:
    Server stack trace: 
       在 System.Runtime.Serialization.FormatterServices.GetSafeUninitializedObject(Type type)
       在 System.Runtime.Serialization.Formatters.Binary.ObjectReader.ParseObject(ParseRecord pr)
       在 System.Runtime.Serialization.Formatters.Binary.ObjectReader.Parse(ParseRecord pr)
       在 System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)
       在 System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)
       在 System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
       在 System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
       在 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
       在 System.Runtime.Remoting.Channels.CoreChannel.DeserializeBinaryRequestMessage(String objectUri, Stream inputStream, Boolean bStrictBinding, TypeFilterLevel securityLevel)
       在 System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)
    Exception rethrown at [0]: 
       在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       在 SG.GameDataGateway.Common.IGameMailService.Test(User u)
       在 WinFormTest.Form1.button1_Click(Object sender, EventArgs e) 位置 F:\project\JoyPort.GameDataGateway\WinFormTest\Form1.cs:行号 166
       在 System.Windows.Forms.Control.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
       在 System.Windows.Forms.Button.WndProc(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.Run(Form mainForm)
       在 WinFormTest.Program.Main() 位置 F:\project\JoyPort.GameDataGateway\WinFormTest\Program.cs:行号 17
       在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.Security.SecurityException
       Message="请求失败。"
       Source="mscorlib"
       GrantedSet=""
       PermissionState="<PermissionSet class=\"System.Security.PermissionSet\"\r\nversion=\"1\"\r\nUnrestricted=\"true\"/>\r\n"
       RefusedSet=""
       Url=""
       StackTrace:
            在 System.Runtime.Serialization.FormatterServices.nativeGetSafeUninitializedObject(RuntimeType type)
            在 System.Runtime.Serialization.FormatterServices.GetSafeUninitializedObject(Type type)
       InnerException: 服务端和客户端配置都加上了<formatter ref="binary" typeFileterLevel="Full" />,配置都没问题.net framework 3.5

解决方案 »

  1.   

    IGameMailService proxy = (IGameMailService)Activator.GetObject(
                    typeof(IGameMailService),
                    "tcp://localhost:3333/Common.ITest"
                    );
                User u = new User(111, "kfdjsakljfk");
                string s = proxy.GetUser(u);
      

  2.   

    IGameMailService proxy = (IGameMailService)Activator.GetObject( 
                    typeof(IGameMailService), 
                    "tcp://localhost:3333/IGameMailService" 
                    ); 
                User u = new User(111, "kfdjsakljfk"); 
                string s = proxy.GetUser(u);
      

  3.   

    在注册通道时,应该将TypeFilterLevel设置为Full