using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Collections.ObjectModel;
using System.Text.Json.Serialization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Debug = System.Console;
readonly Dictionary<string, object> extensionData = new Dictionary<string, object>();
public Dictionary<string, object> ExtensionData { get => extensionData; set => throw new NotImplementedException(); }
public void TestReadOnlyExtensionDataProperty()
var model1 = new Model { ExtensionData = { { "item", "item value" } } };
var json = JsonSerializer.Serialize(model1);
Assert.AreEqual(json, "{\"item\":\"item value\"}");
var model2 = JsonSerializer.Deserialize<Model>(json);
Assert.AreEqual(model1.ExtensionData.Count, model2.ExtensionData.Count, "model2.ExtensionData.Count");
public static void Main()
Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , GetNetCoreVersion());
Console.WriteLine(string.Format("{0} version: {1}", typeof(JsonSerializer).Namespace, typeof(JsonSerializer).Assembly.FullName));
new TestClass().TestReadOnlyExtensionDataProperty();
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];