Git Product home page Git Product logo

Comments (1)

Suremaker avatar Suremaker commented on July 18, 2024

Hello @vadim-kor .

I have updated the package to version 1.1.0. It supports .net461 and netstandard2.1, and from now on it allows serializing/deserializing readonly fields.

A note of comment. If you have been serializing the standard types (like TimeSpan) on applications running on .NetFramework, the values may not deserialize properly on .Net5 / .NetCore

I spot it on test like this:

    public class Tests
    {
        public class MyType
        {
            public DateTime Date { get; set; }
            public TimeSpan Span { get; set; }
            public Dictionary<int, string> Dict { get; set; } = new Dictionary<int, string>();
            public double D { get; set; }
            public int X { get; set; }
        }

        [Test]
        public void Deserialize()
        {
            using var stream = File.OpenRead("..\\out.bin");
            var instance = new ObjectSerializer().Deserialize<MyType>(stream);
            var expected = GetInstance();
            Assert.That(instance.Date, Is.EqualTo(expected.Date));
            Assert.That(instance.D, Is.EqualTo(expected.D));
            Assert.That(instance.Span, Is.EqualTo(expected.Span));
            Assert.That(instance.Dict, Is.EqualTo(expected.Dict));
            Assert.That(instance.X, Is.EqualTo(expected.X));
        }

        [Test]
        public void Serialize()
        {
            var instance = GetInstance();
            using var stream = File.OpenWrite("..\\out.bin");
            new ObjectSerializer().Serialize(stream, instance);
        }

        private static MyType GetInstance() =>
            new MyType
            {
                Date = new DateTime(2005, 07, 30, 16, 57, 49, DateTimeKind.Utc),
                Dict = new Dictionary<int, string> { { 5, "abc" } },
                D = 3.14,
                Span = TimeSpan.FromMilliseconds(23462345.5d),
                X = 55
            };
    }

... where Span value did not match after the deserialization if different runtime was used for serialization and deserialization:

  Expected: 06:31:02.3455000
  But was:  06:31:02.3460000

I presume that in your case you should receive right values as you have been already using the .Net5 with package 1.0.27

from objectserialization-net.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.