Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

[System.Text.Json]Improve error output for unsupported scenarios in System.Text.Json.Serialization #38061

Merged
merged 4 commits into from
May 31, 2019
Merged

[System.Text.Json]Improve error output for unsupported scenarios in System.Text.Json.Serialization #38061

merged 4 commits into from
May 31, 2019

Conversation

MarcoRossignoli
Copy link
Member

@MarcoRossignoli MarcoRossignoli commented May 30, 2019

Contrib to https://github.com/dotnet/corefx/issues/37545

fixes https://github.com/dotnet/corefx/issues/37885 polymorphic interface
fixes https://github.com/dotnet/corefx/issues/37537 parameterless ctor

Exception samples
System.InvalidOperationException : Deserialization of reference type without parameterless constructor is not supported. Type System.Text.Json.Serialization.Tests.ObjectTests+PublicParameterizedConstructorTestClass

System.InvalidOperationException : Deserialization of interface types is not supported. Type System.Text.Json.Serialization.Tests.PolymorphicTests+IThing

cc: @ahsonkhan @steveharter

@MarcoRossignoli MarcoRossignoli changed the title [System.Text.Json]Improve error output for unsupported scenarios in System.Text.Json.Serialization: parameterless constructor [System.Text.Json]Improve error output for unsupported scenarios in System.Text.Json.Serialization May 30, 2019
@MarcoRossignoli
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s), but failed to run 2 pipeline(s).

@MarcoRossignoli
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s), but failed to run 1 pipeline(s).

@MarcoRossignoli
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s), but failed to run 2 pipeline(s).

@MarcoRossignoli
Copy link
Member Author

@safern are there issue with azp?

@safern
Copy link
Member

safern commented May 30, 2019

There might be, I just asked. Do you wanted to run the outerloop legs as well? Maybe close and reopen works?

@MarcoRossignoli
Copy link
Member Author

No I don't need outerloop only regular ci

Copy link
Member

@ahsonkhan ahsonkhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, LGTM

src/System.Text.Json/src/Resources/Strings.resx Outdated Show resolved Hide resolved
src/System.Text.Json/src/Resources/Strings.resx Outdated Show resolved Hide resolved
@MarcoRossignoli
Copy link
Member Author


if (classInfo.CreateObject is null && classInfo.ClassType == ClassType.Object)
{
if (classInfo.Type.IsInterface)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One item to discuss for future checks like this -- should we do these checks during warm-up (when reading properties via reflection) to not affect run-time perf? The disadvantage of doing that is the given property may not actually ever be deserialized if there is never any json payload for that property.

Copy link
Member

@ahsonkhan ahsonkhan May 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this is a "NotSupported" check, I think we should do it up-front and not affect run-time perf. The user should know that their model is not currently supported to avoid surprising behavior when the payload changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

affect run-time perf

Do you have a sense of how impactful this change is to perf? Should we wait till next week or do you think its minimal?

Copy link
Member Author

@MarcoRossignoli MarcoRossignoli May 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One item to discuss for future checks like this -- should we do these checks during warm-up (when reading properties via reflection) to not affect run-time perf? The disadvantage of doing that is the given property may not actually ever be deserialized if there is never any json payload for that property.

I thought about that and I initially did these check on property add...but this could block also "serialization" not only deserialization, so I thought to be close to "delegate usage" to have the check "only" if we want to use that, to have error only if we use it, otherwise we could block some unexpected scenario. I think that first check classInfo.CreateObject is null will be 99% of use cases false it's handled in a good way by jit AFAIK and maybe also by cpu preditcor, so it should be "only"(I know that in context of perf this is offensive 😄) one extra test x, y(not sure but my past test on similar code produce that)

@wtgodbe
Copy link
Member

wtgodbe commented May 31, 2019

Failures are unrelated, merging

picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…ystem.Text.Json.Serialization (dotnet/corefx#38061)

* custom exception for parameterless constructors

* add polymorphic interface exception

* fix ReflectionMaterializer

* address PR feedback


Commit migrated from dotnet/corefx@792eb85
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
5 participants