NullReferenceException for XMPPClient.XMPPAccount


If connect is clicked (ButtonConnect_Click()) when no accounts are provisioned, a NullReferenceException is thrown in the set accessor of XMPPAccount in XMPPClient.cs.
System.NullReferenceException was unhandled
   at PhoneXMPPLibrary.XMPPClient.set_XMPPAccount(XMPPAccount value)
   at XMPPClient.ConnectPage.ButtonConnect_Click(Object sender, EventArgs e)
   at Microsoft.Phone.Shell.ApplicationBarItemContainer.FireEventHandler(EventHandler handler, Object sender, EventArgs args)
   at Microsoft.Phone.Shell.ApplicationBarIconButton.ClickEvent()
   at Microsoft.Phone.Shell.ApplicationBarIconButtonContainer.ClickEvent()
   at Microsoft.Phone.Shell.ApplicationBar.OnCommand(UInt32 idCommand)
   at Microsoft.Phone.Shell.Interop.NativeCallbackInteropWrapper.OnCommand(UInt32 idCommand)

file attachments


jaime7 wrote Feb 4, 2012 at 6:59 PM

Here's a proposed fix.

Since you have the file locked, here's my recommendation for you to put in your version, or if you want to check yours in, I will update my version and check it in with these changes;

  • Added a type check at line 112 to verify the SelectedItem is really an XMPPAccount before I cast it to one.
See attached file and/or code snippet below:
    private void ButtonConnect_Click(object sender, EventArgs e)
        var selectedItem = this.AccountPicker.SelectedItem;

        if (!( selectedItem != null && selectedItem.GetType() == typeof(XMPPAccount)))
            // no accounts have been provisioned yet.
            // show message that says to select an account, or that no accounts have been provisioned
            MessageBox.Show("Please enter your account information");

        App.XMPPClient.XMPPAccount = this.AccountPicker.SelectedItem as XMPPAccount;

        if (App.XMPPClient.XMPPState == PhoneXMPPLibrary.XMPPState.Connected)

jaime7 wrote Feb 4, 2012 at 7:01 PM

PS - if this state isn't sufficient for a "Fixed" status (and I'm not sure it is!) we can only use "Fixed" when an update is checked into source control.

wrote Feb 5, 2012 at 4:09 PM

wrote Feb 14, 2013 at 6:35 PM