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

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

Open
augerhandle opened this issue Feb 7, 2015 · 0 comments

Comments

@augerhandle
Copy link

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant