Bug 36161 - NPE with JSON.NET
Summary: NPE with JSON.NET
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
Depends on:
Reported: 2015-11-23 14:17 UTC by Nuno Cruces
Modified: 2015-11-26 05:39 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Nuno Cruces 2015-11-23 14:17:28 UTC
This code throws an NPE (in the second line) when compiled with Xamarin (5.10) and run on the iOS Simulator (13B137). Newtonsoft.Json 7.0.1 from Nuget. It works when built with Visual Studio and the Xamarin Mac Agent.

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Diagnostics;

var obj = JsonConvert.DeserializeObject<JObject>("{ \"name\": null }");
var name = ((string)obj["name"] ?? "").Trim();

Also, changing the above code to this, fixes it:

var obj = JsonConvert.DeserializeObject<JObject>("{ \"name\": null }");
var name = (string)obj["name"];
name = (name ?? "").Trim();
Comment 1 Sebastien Pouliot 2015-11-23 15:28:04 UTC
That looks like a compiler issue (MS csc vs Mono's mcs)
Comment 2 Nuno Cruces 2015-11-23 15:47:39 UTC
I agree.

I only reported it this way (against Xamarin Studio 5.10) because I couldn't find the specific version of the compiler.
Comment 3 Sebastien Pouliot 2015-11-23 15:51:15 UTC
No problem :-). In doubt just file and we'll figure out where it needs to be fixed. What can be useful is knowing all* the version information (just XS is not enough as it can be used with different versions of Mono and XI, even if most of the time we can deduce which one is the most likely).

* The easiest way to get exact version information is to use the "Xamarin Studio" menu, "About Xamarin Studio" item, "Show Details" button and copy/paste the version informations (you can use the "Copy Information" button).
Comment 4 Nuno Cruces 2015-11-23 15:54:25 UTC
At home now (Europe).
Will report back tomorrow.
Comment 5 Nuno Cruces 2015-11-24 07:58:08 UTC
=== Xamarin Studio ===

Version 5.10 (build 871)
Installation UUID: 6d20facb-a8ce-46a1-a05a-9ae135bafd13
	Mono 4.2.1 (explicit/6dd2d0d)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402010102

=== Xamarin.Profiler ===

Not Installed

=== Apple Developer Tools ===

Xcode 7.1.1 (9081)
Build 7B1005

=== Xamarin.Mac ===

Not Installed

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/Nuno/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.3   (API level 18)
		4.4   (API level 19)
		5.0   (API level 21)
		5.1   (API level 22)
		6.0   (API level 23)

SDK Tools Version: 24.4
SDK Platform Tools Version: 23.0.1
SDK Build Tools Version: 21.1.2

Java SDK: /usr
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

=== Xamarin Android Player ===

Not Installed

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 3c0ec35
Branch: master
Build date: 2015-11-12 13:05:39-0500

=== Build Information ===

Release ID: 510000871
Git revision: 4e9c5abb5ffdae12ba02ac49da83f8b2011dbb88
Build date: 2015-11-12 06:02:54-05
Xamarin addins: 55007ed0e56436f385d8e26394a45be563abc7e8
Build lane: monodevelop-lion-cycle6

=== Operating System ===

Mac OS X 10.10.5
Darwin Nuno-Crucess-MacBook-Air.local 14.5.0 Darwin Kernel Version 14.5.0
    Tue Sep  1 21:23:09 PDT 2015
    root:xnu-2782.50.1~1/RELEASE_X86_64 x86_64
Comment 6 Marek Safar 2015-11-26 05:39:13 UTC
Fixed in master