I have some doubt on .NET exception Serialization, Currently i am working on .NET core 1.1 and .net core 2.0 project where i have some custom exceptions and i have to make those custom exception classes as Serializable ,I have added System.Security.Permissions NameSpace but still i am facing issues after adding the attribute to the class as [Serializable] and while overriding the GetObjectData method.
sample code is below :
[Serializable]
public sealed class TestException: Exception
{
private TestException: ()
{
}
private TestException: (SerializationInfo info, StreamingContext context) : base(info, context)
{
}
[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
{
throw new ArgumentNullException("info");
}
base.GetObjectData(info, context);
}
}
Error1 : The type or namespace name 'SerializationFormatter' could not be found (are you missing a using directive or an assembly reference?) Test.core (netcoreapp1.1)
Error2 :The type or namespace name 'SecurityPermissionAttributeAttribute' could not be found (are you missing a using directive or an assembly reference?) Test.core (netcoreapp1.1)