Skip to content

Instantly share code, notes, and snippets.

@xivSolutions
Created September 13, 2014 00:21
Show Gist options
  • Save xivSolutions/0e41cf6c1c45da1b5bad to your computer and use it in GitHub Desktop.
Save xivSolutions/0e41cf6c1c45da1b5bad to your computer and use it in GitHub Desktop.
Deserialize ModelStateDictionary
Original Stack Overflow Answer from http://stackoverflow.com/a/23506548/586518
Original Code from SO answer:
```csharp
var value = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
{
var obj = new { message = "", ModelState = new Dictionary<string,string[]>() };
var x = JsonConvert.DeserializeAnonymousType(value, obj);
throw new AggregateException(x.ModelState.Select(kvp => new Exception(string.Format("{0}: {1}", kvp.Key, string.Join(". ", kvp.Value)))));
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment