Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error output for unsupported scenarios in System.Text.Json.Serialization #29492

Closed
vcsjones opened this issue May 9, 2019 · 8 comments
Labels
area-System.Text.Json help wanted [up-for-grabs] Good issue for external contributors
Milestone

Comments

@vcsjones
Copy link
Member

vcsjones commented May 9, 2019

S.T.J.Serialization is expected to have a few unsupported scenarios, however this is currently difficult for the developer to diagnose because the error output for such scenarios is usually something along these lines:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Cannot bind to the target method because its signature is not compatible with that of the delegate type.
at System.Delegate.CreateDelegate(Type type, MethodInfo method, Boolean throwOnBindFailure)

As suggested in https://github.com/dotnet/corefx/issues/37522#issuecomment-490916117, this issue is to track improvement of error messages when encountered by the new serialization APIs.

@buyaa-n
Copy link
Contributor

buyaa-n commented May 24, 2019

Another case: when there is no default constructor defined for a class NRE is throwing

public class PublicParameterizedConstructorTestClass
{
    private readonly string _name;
    public PublicParameterizedConstructorTestClass(string name)
    {
        _name = name;
    }
    public string Name
    {
        get { return _name; }
    }
}

[Fact]
public void TestNoDefaultConstuctor() {
    string json = @"{""Name"":""Name!""}";
    Assert.Throws<JsonException>(() =>JsonSerializer.Parse<PublicParameterizedConstructorTestClass>(json));
}

@MarcoRossignoli
Copy link
Member

MarcoRossignoli commented May 29, 2019

@steveharter @ahsonkhan is this up for grabs or there is someone working on?

@ahsonkhan
Copy link
Member

is this up for grabs or there is someone working on?

It's up for grabs. Marking accordingly.

@MarcoRossignoli
Copy link
Member

Link another related issue https://github.com/dotnet/corefx/issues/37188

@Anipik
Copy link
Contributor

Anipik commented Jun 6, 2019

@MarcoRossignoli are you working on it ?

@MarcoRossignoli
Copy link
Member

MarcoRossignoli commented Jun 7, 2019

I worked on some of these here dotnet/corefx#38061
I found other non covered cases with this https://github.com/dotnet/corefx/issues/37188#issuecomment-495267071

@ahsonkhan ahsonkhan self-assigned this Jun 11, 2019
@steveharter
Copy link
Member

I recommend closing this. We should have separate issues for any remaining issues.

@steveharter
Copy link
Member

Closing. Please create new issues for any remaining issues.

@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 3.0 milestone Feb 1, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.Json help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

No branches or pull requests

7 participants