我有一个扩展 MarshalByRefObject 类的类。我创建了一个 HTTPChannel,注册了 ChannelService,并且在读写 int 和 string 属性时一切正常。我的通信类看起来像这样(请注意,这两个类只是一个示例,但我的实际项目看起来非常相似):
public class MyCommunicationClass : MarshalByRefObject
{
public int IntegerValue {get; set;}
public string StringValue {get; set;}
public MyClass[] CustomValueArray {get; set;}
}
我的问题是当我尝试设置为 MyClass[] 属性时发生的异常。MyClass 声明为:
[Serializable]
public class MyClass
{
public string StringValue {get; set;}
}
我收到以下异常:System.Security.SecurityException:请求失败。堆栈跟踪显示:
The method that caused the failure
was:
System.Runtime.Remoting.Channels.ServerProcessing
ProcessMessage(System.Runtime.Remoting.Channels.IServerChannelSinkStack,
System.Runtime.Remoting.Messaging.IMessage,
System.Runtime.Remoting.Channels.ITransportHeaders,
System.IO.Stream,
System.Runtime.Remoting.Messaging.IMessage
ByRef,
System.Runtime.Remoting.Channels.ITransportHeaders
ByRef, System.IO.Stream ByRef)
显示的附加信息:
The action that failed was: Demand The
type of the first permission that
failed was:
System.Security.PermissionSet The
demand was for: <PermissionSet
class="System.Security.PermissionSet"
version="1" Unrestricted="true"/>
The only permitted permissions were:
<PermissionSet
class="System.Security.PermissionSet"
version="1"> <IPermission
class="System.Security.Permissions.SecurityPermission,
mscorlib, Version=4.0.0.0,
Culture=neutral,
PublicKeyToken=b77a5c561934e089"
version="1"
Flags="SerializationFormatter"/>
</PermissionSet>
谁能向我解释发生了什么以及我做错了什么?谢谢!
编辑:这只是我尝试设置MyClass数组时的问题。我可以毫无问题地在 MyCommunicationClass 中分配属性 MyClass 属性。