JSONhttp://blogs.microsoft.co.i.geekswithblogs.net/Aligned/category/15300.aspx
http://json.org/en-USAlignedklogan@omnitech-inc.comSubtext Version 0.0.0.0Tip for a WebApi, Json and System.Net.Http.Formatting exceptionJSONWebApihttp://geekswithblogs.net/Aligned/archive/2015/12/15/tip-for-a-webapi-json-and-system.net.http.formatting-exception.aspx
<p>Originally posted on: <a href='http://geekswithblogs.net/Aligned/archive/2015/12/15/tip-for-a-webapi-json-and-system.net.http.formatting-exception.aspx'>http://geekswithblogs.net/Aligned/archive/2015/12/15/tip-for-a-webapi-json-and-system.net.http.formatting-exception.aspx</a></p><p>My colleague, Brian, had this problem and posted it on our Slack channel. I suggested he share it out further, and since he isn’t blogging yet (I keep encouraging him to do so), I offered to post it for him.</p> <p>He thinks this would mainly happen to something other than an MVC site. In his case it was a console application which didn't have WebApi packages included by default. There was a pretty popular solution that involved by passing the ReadAsAsync&lt;MyModel&gt;() call and instead doing a ReadAsStream() then using <a href="http://json.net/">Json.Net</a> directly to Deserialize the stream into an object, but he found a <strike>better</strike> different way.</p> <p><strong>TIP</strong>: If you are having problems consuming a webAPI with ReadAsAsync&lt;SomeClass&gt;() and you get an error with Newtonsoft.Json and System.Net.Http.Formatting, remove the "old" reference to System.Net.Http.Formatting from your project and install this package: <a href="https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Client/">https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Client/</a></p> <p>Here is the exception he was getting.</p><pre>System.AggregateException was caught</pre><pre> HResult=-2146233088</pre><pre> Message=One or more errors occurred.</pre><pre> Source=mscorlib</pre><pre> StackTrace:</pre><pre> at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)</pre><pre> at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)</pre><pre> at System.Threading.Tasks.Task.Wait()</pre><pre> at &lt;namespace-was-here&gt;.UserInactivityMonitor.Program.Main(String[] args) in &lt;file-path-was-here&gt;\Program.cs:line 33</pre><pre> InnerException: System.IO.FileLoadException</pre><pre> HResult=-2146234304</pre><pre> Message=Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)</pre><pre> Source=System.Net.Http.Formatting</pre><pre> FileName=Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed</pre><pre> FusionLog==== Pre-bind state information ===</pre><pre>LOG: DisplayName = Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed</pre><pre> (Fully-specified)</pre><pre>LOG: Appbase = file:///&lt;file-path-was-here&gt;/bin/Debug/</pre><pre>LOG: Initial PrivatePath = NULL</pre><pre>Calling assembly : System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.</pre><pre>===</pre><pre>LOG: This bind starts in default load context.</pre><pre>LOG: Using application configuration file: &lt;config file name was here&gt;</pre><pre>LOG: Using host configuration file: </pre><pre>LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.</pre><pre>LOG: Post-policy reference: Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed</pre><pre>LOG: Attempting download of new URL file:///&lt;application-path-was-here&gt;/bin/Debug/Newtonsoft.Json.DLL.</pre><pre>WRN: Comparing the assembly name resulted in the mismatch: Major Version</pre><pre>ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.</pre><pre></pre><pre> StackTrace:</pre><pre> at System.Net.Http.Formatting.JsonMediaTypeFormatter..ctor()</pre><pre> at System.Net.Http.Formatting.MediaTypeFormatterCollection.CreateDefaultFormatters()</pre><pre> at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content)</pre><pre> at &lt;namespace-was-here&gt;.UserInactivityController.&lt;GetAccessToken&gt;d__1e.MoveNext() in &lt;file-path-was-here&gt;\UserInactivityController.cs:line 130</pre><pre> --- End of stack trace from previous location where exception was thrown ---</pre><pre> at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)</pre><pre> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)</pre><pre> at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()</pre><pre> at &lt;namesapce-was-here&gt;.UserInactivityController.&lt;GetInactiveUsers&gt;d__b.MoveNext() in &lt;file-path-was-here&gt;\UserInactivityController.cs:line 58</pre><pre> --- End of stack trace from previous location where exception was thrown ---</pre><pre> at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)</pre><pre> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)</pre><pre> at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()</pre><pre> at &lt;namesapce-was-here&gt;.UserInactivityController.&lt;InactivateUsers&gt;d__3.MoveNext() in &lt;file-path-was-here&gt;\UserInactivityController.cs:line 36</pre><pre> --- End of stack trace from previous location where exception was thrown ---</pre><pre> at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)</pre><pre> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)</pre><pre> at System.Runtime.CompilerServices.TaskAwaiter.GetResult()</pre><pre> at &lt;namesapce-was-here&gt;.UserInactivityController.&lt;Run&gt;d__0.MoveNext() in &lt;file-path-was-here&gt;\UserInactivityController.cs:line 29</pre><pre> InnerException: </pre><pre> </pre>Once again, <a href="http://stackoverflow.com/questions/22685530/could-not-load-file-or-assembly-newtonsoft-json-or-one-of-its-dependencies-ma" target="_blank">Stack Overflow was very helpful</a> <a href="http://stackoverflow.com/questions/22130411/reading-httpresponsemessage-content-throws-newtonsoft-json-jsonreaderexception-w" target="_blank">in many questions</a>, but it didn’t give the full answer (which is why I’m posting this).
<img src="http://geekswithblogs.net/Aligned/aggbug/169884.aspx" width="1" height="1" />Alignedhttp://geekswithblogs.net/Aligned/archive/2015/12/15/tip-for-a-webapi-json-and-system.net.http.formatting-exception.aspxTue, 15 Dec 2015 21:18:49 GMThttp://geekswithblogs.net/Aligned/comments/169884.aspxhttp://geekswithblogs.net/Aligned/archive/2015/12/15/tip-for-a-webapi-json-and-system.net.http.formatting-exception.aspx#feedback1http://geekswithblogs.net/Aligned/comments/commentRss/169884.aspxhttp://geekswithblogs.net/Aligned/services/trackbacks/169884.aspxQuick Hint: Formatting JSON for DebuggingToolsJSONhttp://geekswithblogs.net/Aligned/archive/2013/06/25/quick-hint-formatting-json-for-debugging.aspx
<p>Originally posted on: <a href='http://geekswithblogs.net/Aligned/archive/2013/06/25/quick-hint-formatting-json-for-debugging.aspx'>http://geekswithblogs.net/Aligned/archive/2013/06/25/quick-hint-formatting-json-for-debugging.aspx</a></p><p>I needed a way to quickly format JSON that I copied from the Network view in Google Chrome Developer Tools. A co-worker pointed me to the <a href="http://notepad-plus-plus.org/" target="_blank">Notepad++</a> (or use <a href="http://chocolatey.org/packages/notepadplusplus" target="_blank">Chocolatey</a> to install Notepad++) plugin JSMin. Now all I have to do is copy the JSON into Notepad++ and Alt + Ctrl + M and I can see it easily.</p><p>Update: <a href="http://jsonviewer.stack.hu/">http://jsonviewer.stack.hu/</a> is a great online tool. It has a nice visualizing tree view as well.</p> <img src="http://geekswithblogs.net/Aligned/aggbug/153232.aspx" width="1" height="1" />Alignedhttp://geekswithblogs.net/Aligned/archive/2013/06/25/quick-hint-formatting-json-for-debugging.aspxTue, 25 Jun 2013 16:08:08 GMThttp://geekswithblogs.net/Aligned/comments/153232.aspxhttp://geekswithblogs.net/Aligned/archive/2013/06/25/quick-hint-formatting-json-for-debugging.aspx#feedbackhttp://geekswithblogs.net/Aligned/comments/commentRss/153232.aspxhttp://geekswithblogs.net/Aligned/services/trackbacks/153232.aspx