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

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


Attachments

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
Runtime:
	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: 6.0.0.34 (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: 9.2.1.51 (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

Note You need to log in before you can comment on or make changes to this bug.