Skip to content
This repository was archived by the owner on May 16, 2022. It is now read-only.
This repository was archived by the owner on May 16, 2022. It is now read-only.

Problem with C# .NET 6 #135

@ValerioPatane

Description

@ValerioPatane

Hi everyone, I have a big problem with this library, let me explain.
I have a project written in C# .NET Framework 4.8. This project uses ZeroFormatter to serialize very large collections like these:

Collections consist of ILazyDictionary<DateTime, float>
{[{13/02/2022 00:00:00}, 10]}
{[{13/02/2022 00:01:00}, 20]}
{[{13/02/2022 00:02:00}, 30]}
{[{13/02/2022 00:03:00}, 40]}
....

This project works fine, ZeroFormatter serializes and deserializes files without problems.

Now I have another project in C# .NET 6 that have to deserialize the collections above, modify them and save them again re-serializing with ZeroFormatter.

In the .NET 6 project, ZeroFormatter doesn't work, it returns an Error: Bad IL format when serializing, but deserialization works correctly.

I read this solution at this address #112
I downloaded Alexinea.ZeroFormatter where should be the fix. Now the problem is another, when I deserialize files (serialized first with ZeroFormatter), the date is not read correctly but I obtain this:

{[{01/01/0001 00:02:04}, 10]} // The DateTime object is wrong

Another problem, serialize with Alexinea.ZeroFormatter doesn't give problems, but when the file is deserialized by the "old" ZeroFormatter it gives the following error:

Timestamp contains invalid values: Seconds = 637805664000000000; Nanos = 0

This is the StackTrace

   at ZeroFormatter.Internal.BinaryUtil.ReadDateTime (Byte [] & bytes, Int32 offset)
   at ZeroFormatter.Formatters.DateTimeFormatter'1.Deserialize (Byte [] & bytes, Int32 offset, DirtyTracker tracker, Int32 & byteSize)
   at ZeroFormatter.Segments.DictionaryEntry.Create [TTypeResolver, TKey, TValue] (Byte [] bytes, Int32 offset, DirtyTracker tracker, Int32 & byteSize)
   at ZeroFormatter.Formatters.DictionaryEntryFormatter`3.Deserialize (Byte [] & bytes, Int32 offset, DirtyTracker tracker, Int32 & byteSize)
   at ZeroFormatter.Segments.VariableListSegment`2.get_Item (Int32 index)
   at ZeroFormatter.Segments.DictionarySegment`3. <GetEnumerator> d__38.MoveNext ()
   at System.Linq.SystemCore_EnumerableDebugView`1.get_Items ()

Please help me, I need to deserialize the files correctly in .NET 6, serialize them in .NET 6 and deserialize they again in .NET Framework 4.8.

Below there is the serialization and deserialization classes

using System;
using ZeroFormatter;

namespace UploadDemoData.ZeroFormatter.Models
{
    [Serializable]
    [ZeroFormattable]
    public class SampleList
    {
        [Index(0)]
        public virtual ILazyDictionary<DateTime, float> Samples { get; set; }
    }
}
    public class ZeroFormatterOperations
    {
        public static MemoryStream Serialize(Dictionary<DateTime, float> samples)
        {
            SampleList newSample = new SampleList()
            {
                Samples = samples.AsLazyDictionary()
            };

            return new MemoryStream(ZeroFormatterSerializer.Serialize(newSample))
            {
                Position = 0
            };
        }

        public static SampleList Deserialize(MemoryStream memoryStream)
        {
            return ZeroFormatterSerializer.Deserialize<SampleList>(memoryStream);
        }
    }

NB in both my projects (.NET Framework 4.8 and .NET 6) I have installed the latest version (1.6.4) of ZeroFormatter

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions