This is a migrated thread and some comments may be shown as answers.

[Solved] NullReferenceException on closing

2 Answers 145 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Matthias Bibo
Top achievements
Rank 1
Matthias Bibo asked on 02 Oct 2013, 01:27 PM
Hello,

we get a NullReferenceException, when closing a dialog with a RadAutoCompleteBox.
On closing the dialog we call our Dispose() method in the viewmodel, which clears all collections (also the one which is bound to the ItemsSource of the RadAutoCompleteBox). This will result in a NullReferenceException.

Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
StackTrace:
bei Telerik.Windows.Controls.RadAutoCompleteBox.OnItemsSourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
bei System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
bei System.Collections.ObjectModel.ObservableCollection`1.ClearItems()
bei System.Collections.ObjectModel.Collection`1.Clear()
bei Bdl.DialogCrm.Silverlight.ViewModels.ImportManagerViewModel.Dispose()
bei Bdl.DialogCrm.Silverlight.Core.ViewManagement.Bases.ContainerViewModelBase`1.ExecuteCloseViewInstance(ViewInstanceDescription desc)
bei Bdl.DialogCrm.Silverlight.ViewModels.MainViewModel.ExecuteCloseViewInstance(ViewInstanceDescription desc)
bei Microsoft.Practices.Prism.Commands.DelegateCommand`1.<>c__DisplayClass6.<.ctor>b__2(Object o)
bei Microsoft.Practices.Prism.Commands.DelegateCommandBase.Execute(Object parameter)
bei Microsoft.Practices.Prism.Commands.DelegateCommandBase.System.Windows.Input.ICommand.Execute(Object parameter)
bei Telerik.Windows.Controls.RadButton.ExecuteCommand()
bei Telerik.Windows.Controls.RadButton.OnClick()
bei Bdl.DialogCrm.Silverlight.Core.BDLControls.BDLButton.OnClick()
bei System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
bei System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
bei MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName, UInt32 flags)


private void OnItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            string searchText = this.SearchText;
            this.autoCompleteHelper.Populate(searchText);
        }

I looked a the code and I assume, that the Dispose() method ofthe RadAutoCompleteBox was executed and the AutocompleteHelper is null at this moment and should be checked before accessing.

private void OnItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
            string searchText = this.SearchText;
            if (this.autoCompleteHelper != null)
            {
                       this.autoCompleteHelper.Populate(searchText);
            }
}



2 Answers, 1 is accepted

Sort by
0
George
Telerik team
answered on 04 Oct 2013, 12:08 PM
Hello Matthias,

Thank you for pinpointing us this exception with RadAutoCompleteBox. Can you share with us some code so we can reproduce it on our side? This will definitely help us in resolving the problem.

Regards,
George
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Matthias Bibo
Top achievements
Rank 1
answered on 08 Oct 2013, 12:04 PM
Hello,

I showed the code from the RadAutoCompleteBox in Telerik.windows.Controls.dll where the excpetions occured and posted an correction suggestion, but this was for an older version of the dll.

With the newest internal build the failure does not occur anymore.!
I can see in the current version, that this code part has been reworked and uses the FocusManager to check if the Box has the focus.

private void OnItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            this.Populate(this.SearchText);
        }
 
public void Populate(string searchText)
        {
            if (FocusManagerHelper.IsKeyboardFocusWithin(this))
            {
                this.autoCompleteHelper.Populate(searchText);
            }
        }

So this issue is resolved.
Tags
AutoCompleteBox
Asked by
Matthias Bibo
Top achievements
Rank 1
Answers by
George
Telerik team
Matthias Bibo
Top achievements
Rank 1
Share this question
or