The type or namespace name 'SerializationFormatter' could not be found netcoreapp1.1

Viewed 50

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)

1 Answers

If you are using netcoreapp1.1, you are out of luck. BinarySerializer (along with most other serializtion features such as SecurityPermissionAttribute) weren't added to .NET Core until netcoreapp2.0.

Your only choice if you wish to use binary serializtion is to upgrade your app to at least netcoreapp2.0.

NOTE: .NET Core 1.x has been out of support since June 27, 2019. .NET Core 2.x is also out of support since August 21, 2021. .NET Core 3.1 will be out of support on December 13, 2022. See the support docs.

Related