Bug 58801 - DeserializeObject(SerializeObject?) with Newtonsoft and TypeNameHandling = TypeNameHandling.All does not work
Summary: DeserializeObject(SerializeObject?) with Newtonsoft and TypeNameHandling = Ty...
Status: RESOLVED FIXED
Alias: None
Product: Workbooks & Inspector
Classification: Xamarin
Component: Client: Windows ()
Version: 1.3.0 Alpha 1
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: xamarininteractive
URL:
Depends on:
Blocks:
 
Reported: 2017-08-16 07:09 UTC by Andreas Klapperich
Modified: 2017-08-18 20:32 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Sample to reproduce the error (2.96 KB, application/x-xamarin-workbook)
2017-08-16 07:09 UTC, Andreas Klapperich
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Andreas Klapperich 2017-08-16 07:09:55 UTC
Created attachment 24222 [details]
Sample to reproduce the error

var settings = new JsonSerializerSettings { Formatting = Formatting.Indented, TypeNameHandling = TypeNameHandling.All };
var text2 = JsonConvert.SerializeObject(Container, settings);
var obj2 = JsonConvert.DeserializeObject<ContainerClass>(text2, settings);

That is the normal output of text1
{
  "$type": "ConsoleApp2.ContainerClass, ConsoleApp2",
  "Items": {
    "$type": "System.Collections.Generic.List`1[[ConsoleApp2.CoreContainer, ConsoleApp2]], mscorlib",

This is the Output of of text2 from the workbook
{ 
 "$type": "🐵0003#0-1+ContainerClass, 🐵0003#0-1", 
 "Items": { 
 "$type": "System.Collections.Generic.List`1[[🐵0003#0-1+CoreContainer, 🐵0003#0-1]], mscorlib",

and this is the error after the DeserializeObject of text2 on the workbook
JsonSerializationException: Error resolving type specified in JSON '🐵0003#0-1+ContainerClass, 🐵0003#0-1'. Path '$type', line 2, position 50............
Comment 1 Sandy Armstrong [MSFT] 2017-08-16 22:41:59 UTC
Thanks!

All types defined in a workbook are happening in a host object, which is the monkey/number thing you're seeing. We'll look into how we can prevent this issue.
Comment 2 Andreas Klapperich 2017-08-17 14:21:01 UTC
FYI

It works on a Mac 

WorkBook Version 1.2.2
Comment 3 Bojan Rajkovic [MSFT] 2017-08-18 20:32:21 UTC
This should be fixed in an upcoming release. Thank you for the detailed bug report and including the sample workbook!