Search code examples
c#arraysserializationuwpbinaryformatter

uwp anniversary update Binary formatter


I cannot find Binary Formatter class in uwp project targeting anniversary sdk. The issue is I need to share a helper class with some methods which uses Binary Formatter between 3 projects 1. webapi ( dotner core 3 ) 2. uwp main app ( 1809 sdk ) 3. uwp side app ( anniversary sdk )

now the binary formatter is by default available in 1st 2 projects but in the third one it causes compile error. I am using this helper class for encryption basically.

Code

private byte[] ConvertIntoByte(object value)
{
    using (var ms = new MemoryStream())
    {
        var bf = new BinaryFormatter();
        bf.Serialize(ms, value ?? "null");
        return ms.ToArray();
    }
}

Solution

  • now the binary formatter is by default available in 1st 2 projects but in the third one it causes compile error.

    The problem is that BinaryFormatter class only applies to .Net Standard 2.0 2.1. It means that the minimum UWP support version is 16299. So please modify your side app target minimum version to 16299. Or install third-part lib such as EcoCore.