Is there an alternative to BinaryFormatter that works in a trust environment

I am launching a website in a hosted environment (i.e. I have no control over permissions) and it is configured to run in a trust environment. The code that I use serializes the object to be stored in the database and uses BinaryFormatter. However, this leads to a SecurityException running under average trust.

Is there an alternative binary formatter that will work under average trust?

+3
source share
2 answers

Thanks for the comments. For those who are interested, I ended up using Newtonsofts JsonSerializer with BsonWriter, which works in average trust. See the example below:

public object Deserialize<T>(System.IO.Stream serializationStream)
{
    JsonSerializer serializer = new JsonSerializer();
    T instance;

    BsonReader reader = new BsonReader(serializationStream);
    instance = serializer.Deserialize<T>(reader);

    return instance;
}

public void Serialize(System.IO.Stream serializationStream, object graph)
{
    JsonSerializer serializer = new JsonSerializer();

    using (BsonWriter writer = new BsonWriter(serializationStream))
    {
        serializer.Serialize(writer, graph);
    }
}
+3
source

BinaryFormatter . .NET Framework , :

XmlSerializer DataContractSerializer , , , , . .NET. NetDataContractSerializer .NET Framework, , . , .NET, .

, , . . http://msdn.microsoft.com/en-us/library/bb412175.aspx.

+3

Source: https://habr.com/ru/post/1792572/


All Articles