using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.Globalization;
using System.Runtime.Serialization;
public struct struct_realTime
public int indexNum { get; set; }
public string currentTime { get; set; }
public string currentType { get; set; }
public static void Test()
var path = "Question58780225.bin";
foreach (var count in new [] { 1, 2, 14, 15, 16, 17, ushort.MaxValue - 4, ushort.MaxValue + 4 })
static void Test(string filename, int expectedNumberOfRootItemsInFile)
List<struct_realTime> list_temp = new List<struct_realTime>(innerCount);
for (int num=0; num < innerCount; num++)
list_temp.Add(new struct_realTime
Console.WriteLine("Testing: {0} repetitions of {1}", expectedNumberOfRootItemsInFile, MessagePackSerializer.ToJson(list_temp));
for (int i = 0; i < expectedNumberOfRootItemsInFile; i++)
using (var fileStream = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite))
MessagePackSerializer.Serialize(fileStream, list_temp);
List<List<struct_realTime>> allItemsInFile = new List<List<struct_realTime>>();
using (var fileStream = File.OpenRead(filename))
while (fileStream.Position < fileStream.Length)
allItemsInFile.Add(MessagePackSerializer.Deserialize<List<struct_realTime>>(fileStream));
Assert.IsTrue(allItemsInFile.Count == expectedNumberOfRootItemsInFile);
Assert.IsTrue(allItemsInFile.All(i => i.SequenceEqual(list_temp)));
Console.WriteLine(" Tests passed.");
public static void Main()
Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , GetNetCoreVersion());
Console.WriteLine("MessagePack version: " + typeof(MessagePackSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");
public static string GetNetCoreVersion()
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];