From ac60693cbd5fc78d6a1bf8bf8fd916305f4de30d Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Tue, 16 Oct 2018 09:54:47 -0400 Subject: [PATCH] [mediaplayer] Fix NRE in MPNowPlayingInfoCenter wrt null dictionary entries. Fixes #4988 The custom `TryGetValue` could return `true` and an `out null`. That was fine for many items, e.g. converting `null` to `NSString` or `NSDate` is fine. However this cause an `NullReferenceException` when trying to create arrays (thru `NSArray`) or converting `NSNumber` into value types. The _normal_ `TryGetValue` behavior fixes this - and avoid extraneous (and non-required) conversions of `null` items. ref: https://github.com/xamarin/xamarin-macios/issues/4988 --- src/MediaPlayer/MPNowPlayingInfoCenter.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/MediaPlayer/MPNowPlayingInfoCenter.cs b/src/MediaPlayer/MPNowPlayingInfoCenter.cs index bec879b5c162..d9064899b151 100644 --- a/src/MediaPlayer/MPNowPlayingInfoCenter.cs +++ b/src/MediaPlayer/MPNowPlayingInfoCenter.cs @@ -210,13 +210,10 @@ internal MPNowPlayingInfo (NSDictionary source) bool TryGetValue (NSDictionary source, NSObject key, out NSObject result) { - var b = false; result = null; - if (key != null) { - source.TryGetValue (key, out result); - b = true; - } - return b; + if (key != null) + return source.TryGetValue (key, out result); + return false; } }