J
jehugaleahsa
Hello:
I am implementing a custom exception class and it exposes an interface
property. I want the property to be reinitialized when deserializing.
This is what my constructor and my GetObjectData look like:
protected CustomException(SerializationInfo info,
StreamingContext context)
: base(info, context)
{
_custom = (ICustom)info.GetValue("Custom", typeof
(ICustom));
}
[SecurityPermission(SecurityAction.LinkDemand,
Flags=SecurityPermissionFlag.SerializationFormatter)]
public override void GetObjectData(SerializationInfo info,
StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("Custom", _custom, typeof(ICustom));
}
ICustom is the interface I am exposing with a read-only property. The
concrete class is serializable:
public ICustom Custom
{
get
{
return _custom;
}
}
I want to make sure that no matter who is deserializing my exception
they will not lose this property. Can the deserializer detect the
actual type? can it create it? I see in the same process this works
fine. But what about across processes or a network?
First, will this work? Second, could someone explain to me how it
knows how to deserialize it into the correct type? Third, is there a
best practice for this kind of thing?
Thanks for any insight!
I am implementing a custom exception class and it exposes an interface
property. I want the property to be reinitialized when deserializing.
This is what my constructor and my GetObjectData look like:
protected CustomException(SerializationInfo info,
StreamingContext context)
: base(info, context)
{
_custom = (ICustom)info.GetValue("Custom", typeof
(ICustom));
}
[SecurityPermission(SecurityAction.LinkDemand,
Flags=SecurityPermissionFlag.SerializationFormatter)]
public override void GetObjectData(SerializationInfo info,
StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("Custom", _custom, typeof(ICustom));
}
ICustom is the interface I am exposing with a read-only property. The
concrete class is serializable:
public ICustom Custom
{
get
{
return _custom;
}
}
I want to make sure that no matter who is deserializing my exception
they will not lose this property. Can the deserializer detect the
actual type? can it create it? I see in the same process this works
fine. But what about across processes or a network?
First, will this work? Second, could someone explain to me how it
knows how to deserialize it into the correct type? Third, is there a
best practice for this kind of thing?
Thanks for any insight!