Repository navigation
Description
After setting a subset of properties on MPNowPlayingInfoCenter.DefaultCenter.NowPlaying, it can no longer be retrieved without a NullReferenceException thrown from the getter for NowPlaying.
Occurs on both Mac (10.13 and 10.14) and iOS (12.0 device and simulator).
Steps to Reproduce
- Set a value on the MPNowPlayingInfoCenter, for example,
MPNowPlayingInfoCenter.DefaultCenter.NowPlaying.Title = "Title";
- Retrieve the now playing info, for example:
var npInfo = MPNowPlayingInfoCenter.DefaultCenter.NowPlaying;
- Get a NullReferenceException in MPNowPlayingInfoCenter.cs
Expected Behavior
We should be able to retrieve the NowPlayingInfo from MPNowPlayingInfoCenter.DefaultCenter when some but not all of its properties are non-null.
Actual Behavior
After setting a subset of properties, this exception is thrown (iOS in this case) when you try to read MPNowPlayingInfoCenter.DefaultCenter.NowPlaying:
System.NullReferenceException: Object reference not set to an instance of an object
at MediaPlayer.MPNowPlayingInfo..ctor (Foundation.NSDictionary source) [0x000f8] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.0.26/src/Xamarin.iOS/MediaPlayer/MPNowPlayingInfoCenter.cs:161
at MediaPlayer.MPNowPlayingInfoCenter.get_NowPlaying () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.0.26/src/Xamarin.iOS/MediaPlayer/MPNowPlayingInfoCenter.cs:227
at appfiddle.ViewController.ViewDidLoad () [0x00067] in /Users/johnm/Dropbox/Projects/fiddle/appfiddle/appfiddle/ViewController.cs:34
at at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.0.26/src/Xamarin.iOS/UIKit/UIApplication.cs:79
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.0.26/src/Xamarin.iOS/UIKit/UIApplication.cs:63
at appfiddle.Application.Main (System.String[] args) [0x00001] in /Users/johnm/Dropbox/Projects/fiddle/appfiddle/appfiddle/Main.cs:12
The exact line number varies depending on how many properties are set.
In MPNowPlayingInfoCenter.cs, TryGetValue() is returning true, but the result out param is null.
Environment
Below is the current beta, but this also happens with the latest from the stable channel.
=== Visual Studio Professional 2017 for Mac (Preview) ===
Version 7.7 Preview (7.7 build 1470)
Installation UUID: 72ef31f8-1db6-474f-b1a1-36ea425445d5
Runtime:
Mono 5.16.0.173 (2018-06/910395a05f6) (64-bit)
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 4.4.1.178 (master / eeaeb7e6)
Package version: 516000173
=== NuGet ===
Version: 4.3.1.4445
=== .NET Core ===
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
2.1.4
2.1.3
2.1.1
SDK: /usr/local/share/dotnet/sdk/2.1.402/Sdks
SDK Versions:
2.1.402
2.1.401
2.1.301
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.16.0/lib/mono/msbuild/15.0/bin/Sdks
=== Xamarin.Profiler ===
Version: 1.6.4
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler
=== Xamarin.Android ===
Version: 9.1.0.29 (Visual Studio Professional)
Android SDK: /Users/johnm/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
8.1 (API level 27)
SDK Tools Version: 26.1.1
SDK Platform Tools Version: 27.0.1
SDK Build Tools Version: 27.0.3
Java SDK: /Users/johnm/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.9
openjdk version "1.8.0-9"
OpenJDK Runtime Environment (build 1.8.0-9-microsoft-b00)
OpenJDK 64-Bit Server VM (build 25.71-b00, mixed mode)
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL
=== Android Device Manager ===
Version: 7.7.1.0
Hash: a173bd27
=== Xamarin Inspector ===
Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1
=== Apple Developer Tools ===
Xcode 10.0 (14320.24)
Build 10A254a
=== Xamarin.Mac ===
Version: 5.2.0.0 (Visual Studio Professional)
Hash: 930b5168
Branch:
Build date: 2018-09-27 17:09:32-0400
=== Xamarin.iOS ===
Version: 12.2.0.26 (Visual Studio Professional)
Hash: 204c23333
Branch: d15-9
Build date: 2018-09-20 10:54:35-0400
=== Build Information ===
Release ID: 707001470
Git revision: 7aff2dc1f28d711d11d63d79b2a4c49cda217189
Build date: 2018-09-28 17:39:40+00
Build branch: release-7.7-preview3
Xamarin extensions: ab5106e52c8cb870de8b90dfc0f298e00a37051d
=== Operating System ===
Mac OS X 10.13.6
Darwin 17.7.0 Darwin Kernel Version 17.7.0
Thu Jun 21 22:53:14 PDT 2018
root:xnu-4570.71.2~1/RELEASE_X86_64 x86_64
Activity
spouliot commentedon Oct 16, 2018
Thanks for your test case! I can reproduce the issue.
Yes, that does not seem logic - I'll dig it there was an original reason for this. Thanks!
spouliot commentedon Oct 16, 2018
So it's because
nullis valid in most cases and can be converted intoNSString,NSDate...However we can't get an
Handleout ofnullto create arrays (thruNSArray) so those (2) cases needs an extra check.[mediaplayer] Fix NRE in MPNowPlayingInfoCenter wrt null dictionary e…
[mediaplayer] Fix NRE in MPNowPlayingInfoCenter wrt null dictionary e…
[mediaplayer] Fix NRE in MPNowPlayingInfoCenter wrt null dictionary e…
Squashed commit of the following:
Squashed commit of the following:
Squashed commit of the following: