Skip to content
This repository was archived by the owner on Apr 26, 2020. It is now read-only.

passing JsonNetBodyDeserializer to result.Body.Deserialize throws ArgumentNullExceptionΒ #20

@augerhandle

Description

@augerhandle

In a test I am writing, I have some assertions on the deserialized JSON that I get back from my API. The deserialization and assert looks like this:

var output = result.Body.Deserialize<MyOutput>(new JsonNetBodyDeserializer());
Assert.That( output... );

Unfortunately, I never get to the assert. Instead, I get an ArgumentNullException from System.Linq.Enumerable.

Here's how that happens. When result.Body.Deserialize() executes, it has the following code in it:

var bindingContext = new BindingContext { DestinationType = typeof(TModel) };
return (TModel)bodyDeserializer.Deserialize(bodyWrapper.ContentType, bodyWrapper.AsStream(), bindingContext);

Notice in particular the only property defined in bindingContext is DestinationType. In particular the ValidModelBindingMembers property is null.

Now, when the JsonNetBodyDeserializer Deserialize() method is executed, there is code in there that looks like this:

if (properties.Concat(fields).Except(context.ValidModelBindingMembers).Any()){...}

In other words, the argument to Except() is null, which immediately causes Except() to throw an exception.

My conclusion is that JsonNetBodyDeserializer is guarenteed never to work in this scenario.

Is this a bug, or am I somehow misusing the class in the first place?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions