一个诡异的Remoting问题,“由于安全限制,无法访问类型”

lingyun_k 2009-09-14 11:30:55
实体类
[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



...全文
228 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
lingyun_k 2009-09-16
  • 打赏
  • 举报
回复
问题已解决,强名称程序集的问题
yuyingying1986 2009-09-14
  • 打赏
  • 举报
回复
你要发服务端的代码来看,不是客户端的
xinghuanonline 2009-09-14
  • 打赏
  • 举报
回复
路过
yuyingying1986 2009-09-14
  • 打赏
  • 举报
回复
在注册通道时,应该将TypeFilterLevel设置为Full
lingyun_k 2009-09-14
  • 打赏
  • 举报
回复
IGameMailService proxy = (IGameMailService)Activator.GetObject(
typeof(IGameMailService),
"tcp://localhost:3333/IGameMailService"
);


User u = new User(111, "kfdjsakljfk");
string s = proxy.GetUser(u);
haihuan23 2009-09-14
  • 打赏
  • 举报
回复
lingyun_k 2009-09-14
  • 打赏
  • 举报
回复
IGameMailService proxy = (IGameMailService)Activator.GetObject(
typeof(IGameMailService),
"tcp://localhost:3333/Common.ITest"
);


User u = new User(111, "kfdjsakljfk");
string s = proxy.GetUser(u);
jimmy_jpy 2009-09-14
  • 打赏
  • 举报
回复
贴个具体代码看看呢,谢谢
lingyun_k 2009-09-14
  • 打赏
  • 举报
回复
服务端的配置和代码不会有任何问题

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧