This project has moved and is read-only. For the latest updates, please go here.

System.NullReferenceException in GlobalPlatformServices.Default.GetRandomNumber

Mar 5, 2014 at 11:41 AM
While playing this media stream "", Null-Ref exception always ocurred. (Maybe you can repro at this time.)

By debugging, I could find the problem at this line,
                if (retry)
                    var actualDelay = (int)(delay * (0.5 + GlobalPlatformServices.Default.GetRandomNumber()));  // <<==== Null-Ref Ex!!!

                    delay += delay;

                    await TaskEx.Delay(actualDelay, cancellationToken).ConfigureAwait(false);
GlobalPlatformServices.Default instance is null.
Mar 5, 2014 at 1:30 PM
Are you possibly missing some initialization code?

From SamplePlayer..WP8/App.xaml.cs:
        public App()
            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            GlobalPlatformServices.Default = new PlatformServices();

            // Standard XAML initialization
The PlatformServices provide a couple of things that Portable Class Libraries can't access directly. Now that a DI container is available, this should be handled by constructor injection instead of a global variable.

In the meantime, could you try adding the initialization code to see if it solves your problem?
    GlobalPlatformServices.Default = new PlatformServices();
Anywhere before you start playback is fine.
Marked as answer by SeongTaeJeong on 3/5/2014 at 5:58 AM
Mar 5, 2014 at 1:32 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Mar 5, 2014 at 2:03 PM
Thanks for your answer.

I add the source code and now playing well. Sorry for my trivial mistake. I used your source codes from HlsView.Win81 project, but I couldn't expect the modification in App.xaml.cs file.

Now, phoesm is perfectly going well with my media-streaming environments.

Thanks again. :)
Mar 5, 2014 at 7:20 PM
You're welcome.

I've forgotten to set GlobalPlatformServices.Default myself. Since there is no good reason for it anymore with the recent IoC/DI changes, it really needs to go away. Until after I get this next build out, I think I'll put something in MediaStreamFascade to make sure that GlobalPlatformServices.Default is initialized.
Mar 5, 2014 at 10:57 PM
10af8d336c61 should make is unnecessary to initialize GlobalPlatformServices.Default. I'll try to get rid of it at some point in the future.