{"action":"created","issue":{"url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/1294","repository_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json","labels_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/1294/labels{/name}","comments_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/1294/comments","events_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/1294/events","html_url":"https://github.com/JamesNK/Newtonsoft.Json/issues/1294","id":224019251,"number":1294,"title":".NET Core 2.0 (preview) regression compared to .NET Core 1.1","user":{"login":"JustArchi","id":1069029,"avatar_url":"https://avatars3.githubusercontent.com/u/1069029?v=3","gravatar_id":"","url":"https://api.github.com/users/JustArchi","html_url":"https://github.com/JustArchi","followers_url":"https://api.github.com/users/JustArchi/followers","following_url":"https://api.github.com/users/JustArchi/following{/other_user}","gists_url":"https://api.github.com/users/JustArchi/gists{/gist_id}","starred_url":"https://api.github.com/users/JustArchi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JustArchi/subscriptions","organizations_url":"https://api.github.com/users/JustArchi/orgs","repos_url":"https://api.github.com/users/JustArchi/repos","events_url":"https://api.github.com/users/JustArchi/events{/privacy}","received_events_url":"https://api.github.com/users/JustArchi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-04-25T04:40:25Z","updated_at":"2017-04-25T05:11:53Z","closed_at":null,"body":".NET Core 2.0 is not released yet, so there is no reason to panic, but I spotted a pretty nasty regression which probably should be looked into, assuming it's not .NET core 2.0 bug.\r\n\r\n### Source/destination types\r\n\r\n```csharp\r\nConcurrentDictionary<byte, string>\r\n```\r\n\r\n### Source/destination JSON\r\n\r\n```javascript\r\n{\"TestDictionary\":{\"0\":\"0\"}}\r\n```\r\n\r\n### Expected behavior\r\n\r\nProper deserialization of json to `ConcurrentDictionary<byte, string>`.\r\n\r\n### Actual behavior\r\n\r\n```\r\nUnhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.\r\n   at System.Collections.Concurrent.ConcurrentDictionary`2.InitializeFromCollection(IEnumerable`1 collection)\r\n   at System.Collections.Concurrent.ConcurrentDictionary`2.OnDeserialized(StreamingContext context)\r\n   --- End of inner exception stack trace ---\r\n   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)\r\n   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)\r\n   at Newtonsoft.Json.Serialization.JsonContract.InvokeOnDeserialized(Object o, StreamingContext context)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateDictionary(IDictionary dictionary, JsonReader reader, JsonDictionaryContract contract, JsonProperty containerProperty, String id)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)\r\n   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)\r\n   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)\r\n   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)\r\n   at test.Program.Main()\r\n```\r\n\r\n### Steps to reproduce\r\n\r\n```csharp\r\nusing System;\r\nusing System.Collections.Concurrent;\r\nusing Newtonsoft.Json;\r\n\r\nnamespace test {\r\n\tinternal static class Program {\r\n\t\tprivate static void Main() {\r\n\t\t\tTestObject o1 = new TestObject();\r\n\t\t\to1.TestDictionary[0] = \"0\";\r\n\t\t\tstring json = JsonConvert.SerializeObject(o1);\r\n\r\n\t\t\tTestObject o2 = JsonConvert.DeserializeObject<TestObject>(json);\r\n\t\t}\r\n\r\n\t\tinternal sealed class TestObject {\r\n\t\t\t[JsonProperty]\r\n\t\t\tinternal readonly ConcurrentDictionary<byte, string> TestDictionary = new ConcurrentDictionary<byte, string>();\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\nWith .NET Core 1.1 csproj file such as:\r\n\r\n```\r\n<Project Sdk=\"Microsoft.NET.Sdk\">\r\n\r\n  <PropertyGroup>\r\n    <OutputType>Exe</OutputType>\r\n    <TargetFramework>netcoreapp1.1</TargetFramework>\r\n  </PropertyGroup>\r\n\r\n  <ItemGroup>\r\n    <PackageReference Include=\"Newtonsoft.Json\" Version=\"10.0.2\" />\r\n  </ItemGroup>\r\n\r\n</Project>\r\n```\r\n\r\nEverything works fine.\r\n\r\nIf we switch `<TargetFramework>` from `netcoreapp1.1` to `netcoreapp2.0` and try to build with latest .NET Core preview bits, previously flawless result quickly changes into unhandled exception.\r\n\r\nI'm not entirely sure whether this is change of some internal API that Newtonsoft.Json is using (that should be adapted), or whether this is actual .NET Core 2.0 bug that should be forwarded, but judging from amount of passing tests for .NET Core, I'm pretty sure this is simply Newtonsoft.Json incompatibility that should be corrected here, hence I'm reporting an issue.\r\n\r\nI'd be very grateful if you could look into this, as .NET Core 2.0 is supposed to be released pretty soon, and I'm sure that many people will attempt to use the library with it, as there is no net standard incompatibility with upcoming version.\r\n\r\nP.S. **[this](https://github.com/dotnet/corefx/commit/0e62a603d1579eb5996caed44d8f1ae02ed5d76a)** commit could have something to do with it.\r\n\r\nThank you in advance!\r\n\r\n```\r\n.NET Command Line Tools (2.0.0-preview2-005840)\r\n\r\nProduct Information:\r\n Version:            2.0.0-preview2-005840\r\n Commit SHA-1 hash:  8f2fcef544\r\n\r\nRuntime Environment:\r\n OS Name:     debian\r\n OS Version:  9\r\n OS Platform: Linux\r\n RID:         ubuntu.16.10-x64\r\n Base Path:   /opt/dotnet/sdk/2.0.0-preview2-005840/\r\n\r\nMicrosoft .NET Core Shared Framework Host\r\n\r\n  Version  : 2.0.0-preview1-002061-00\r\n  Build    : 2b70ec9c3b014af0c2a5f45de0e5b73a1ae51c09\r\n```"},"comment":{"url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/comments/296910198","html_url":"https://github.com/JamesNK/Newtonsoft.Json/issues/1294#issuecomment-296910198","issue_url":"https://api.github.com/repos/JamesNK/Newtonsoft.Json/issues/1294","id":296910198,"user":{"login":"JamesNK","id":303201,"avatar_url":"https://avatars1.githubusercontent.com/u/303201?v=3","gravatar_id":"","url":"https://api.github.com/users/JamesNK","html_url":"https://github.com/JamesNK","followers_url":"https://api.github.com/users/JamesNK/followers","following_url":"https://api.github.com/users/JamesNK/following{/other_user}","gists_url":"https://api.github.com/users/JamesNK/gists{/gist_id}","starred_url":"https://api.github.com/users/JamesNK/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JamesNK/subscriptions","organizations_url":"https://api.github.com/users/JamesNK/orgs","repos_url":"https://api.github.com/users/JamesNK/repos","events_url":"https://api.github.com/users/JamesNK/events{/privacy}","received_events_url":"https://api.github.com/users/JamesNK/received_events","type":"User","site_admin":false},"created_at":"2017-04-25T05:11:53Z","updated_at":"2017-04-25T05:11:53Z","body":"Thanks. I can put a fix in Json.NET but I'll also log it with MS and see whether they want a fix ConcurrentDictionary properly."}}
{"actor":{"display_login":"JamesNK"}}