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

RadTreeView crashes the application

3 Answers 184 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
prakash
Top achievements
Rank 1
prakash asked on 19 Jun 2009, 05:42 AM

Dear Friends,

I have a windows forms application. I hosted the the "RadTreeView" inside a windows form using an "ElementHost" control. if I click on the treeview item I got an "NullReferenceException" in the "RadTreeView_GotFocus" method. By checking the source code of the method we found the problem. 

The "Application.Current" is always null for a WinForms Applicaiton. So an exception throws on the first line of the code. Since It is unhandled It crashed the application.

Is there any workaround or solution to the above problem? I have attched the exception call stack too.

RadTreeView_GotFocus Method Source
-----
private void RadTreeView_GotFocus(object sender, RoutedEventArgs e)
{
    if (Application.Current.MainWindow != null)
    {
        Application.Current.MainWindow.MouseWheel += new MouseWheelEventHandler(this.OnRootVisualMouseWheel);
    }
    if (e.OriginalSource == this)
    {
        if (this.SelectedContainer != null)
        {
            this.SelectedContainer.Focus();
        }
        else
        {
            RadTreeViewItem item = base.ItemContainerGenerator.ContainerFromIndex(0) as RadTreeViewItem;
            if (item != null)
            {
                item.Focus();
            }
        }
    }
    this.IsSelectionActive = true;
}

Steps To reproduce 

1. Create a WinForms Application (Target Framework to .NET 3.5)
1a. Add a reference to these dlls (Telerik.Windows.Controls & Telerik.Windows.Controls.Navigation)
2. Add a WPF UserControl to the project. And add the following XAML.
       <telerik:RadTreeView >
            <telerik:RadTreeViewItem Header="Sony"  >
                <telerik:RadTreeViewItem Header="Vaio"  />
                <telerik:RadTreeViewItem Header="Bravia"  />
            </telerik:RadTreeViewItem>
        </telerik:RadTreeView>
3. Add a "ElementHost" control to the exisiting "Form1 (Windows Form)". 
4. Build the project
5. Set the child property of the ElementHost to an instance of the WPF UserControl we created.
6. Build and Run the application.
7. Click over a treeviewitem. 
8. The application will crash.

Runtime Details
Windows Vista 32 bit Business Edition
VS.NET 2008 Professional With SP1
.NET Framework 3.5 SP1
Telereik Version : 2009.1.424.35 (both Telerik.Windows.Controls & Telerik.Windows.Controls.Navigation)

The exception call stack.
 Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.RadTreeView.RadTreeView_GotFocus(object sender = {Telerik.Windows.Controls.RadTreeView Items.Count:1}, System.Windows.RoutedEventArgs e = {System.Windows.RoutedEventArgs}) + 0x2a bytes 
  PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs) + 0x78 bytes 
  PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source = {Sony}, System.Windows.RoutedEventArgs args = {System.Windows.RoutedEventArgs}, bool reRaised = false) + 0x1bf bytes 
  PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender = {Sony}, System.Windows.RoutedEventArgs args = {System.Windows.RoutedEventArgs}) + 0x79 bytes 
  PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs e) + 0x17 bytes 
  PresentationCore.dll!System.Windows.UIElement.OnGotFocus(System.Windows.RoutedEventArgs e) + 0x5 bytes 
  PresentationFramework.dll!System.Windows.FrameworkElement.OnGotFocus(System.Windows.RoutedEventArgs e) + 0x4c bytes 
  PresentationCore.dll!System.Windows.UIElement.IsFocused_Changed(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs e) + 0xa2 bytes 
  WindowsBase.dll!System.Windows.DependencyObject.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) + 0x4a bytes 
  PresentationFramework.dll!System.Windows.FrameworkElement.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) + 0x50 bytes 
  WindowsBase.dll!System.Windows.DependencyObject.NotifyPropertyChange(System.Windows.DependencyPropertyChangedEventArgs args) + 0x2c bytes 
  WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex entryIndex = {System.Windows.EntryIndex}, System.Windows.DependencyProperty dp = {IsFocused}, System.Windows.PropertyMetadata metadata, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry = {System.Windows.EffectiveValueEntry}, bool coerceWithDeferredReference, System.Windows.OperationType operationType) + 0x515 bytes 
  WindowsBase.dll!System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty dp, object value, System.Windows.PropertyMetadata metadata, bool coerceWithDeferredReference, System.Windows.OperationType operationType, bool isInternal) + 0x1eb bytes 
  WindowsBase.dll!System.Windows.DependencyObject.SetValue(System.Windows.DependencyPropertyKey key, object value) + 0x39 bytes 
  PresentationCore.dll!System.Windows.Input.FocusManager.OnFocusedElementChanged(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs e) + 0xf0 bytes 
  WindowsBase.dll!System.Windows.DependencyObject.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) + 0x4a bytes 
  PresentationFramework.dll!System.Windows.FrameworkElement.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) + 0x50 bytes 
  WindowsBase.dll!System.Windows.DependencyObject.NotifyPropertyChange(System.Windows.DependencyPropertyChangedEventArgs args) + 0x2c bytes 
  WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex entryIndex = {System.Windows.EntryIndex}, System.Windows.DependencyProperty dp = {FocusedElement}, System.Windows.PropertyMetadata metadata, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry = {System.Windows.EffectiveValueEntry}, bool coerceWithDeferredReference, System.Windows.OperationType operationType) + 0x515 bytes 
  WindowsBase.dll!System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty dp, object value, System.Windows.PropertyMetadata metadata, bool coerceWithDeferredReference, System.Windows.OperationType operationType, bool isInternal) + 0x1eb bytes 
  WindowsBase.dll!System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty dp, object value) + 0x2e bytes 
  PresentationCore.dll!System.Windows.Input.FocusManager.SetFocusedElement(System.Windows.DependencyObject element, System.Windows.IInputElement value) + 0x2f bytes 
  PresentationFramework.dll!System.Windows.Input.KeyboardNavigation.UpdateFocusedElement(System.Windows.DependencyObject focusTarget = {Sony}) + 0x32 bytes 
  PresentationFramework.dll!System.Windows.FrameworkElement.OnGotKeyboardFocus(object sender, System.Windows.Input.KeyboardFocusChangedEventArgs e = {System.Windows.Input.KeyboardFocusChangedEventArgs}) + 0x47 bytes 
  PresentationCore.dll!System.Windows.Input.KeyboardFocusChangedEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget) + 0x34 bytes 
  PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) + 0x27 bytes 
  PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs) + 0x3e bytes 
  PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source = {Sony}, System.Windows.RoutedEventArgs args = {System.Windows.Input.KeyboardFocusChangedEventArgs}, bool reRaised = false) + 0x1bf bytes 
  PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender = {Sony}, System.Windows.RoutedEventArgs args = {System.Windows.Input.KeyboardFocusChangedEventArgs}) + 0x79 bytes 
  PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs args = {System.Windows.Input.KeyboardFocusChangedEventArgs}, bool trusted) + 0x35 bytes 
  PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea() + 0x311 bytes 
  PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input) + 0x42 bytes 
  PresentationCore.dll!System.Windows.Input.KeyboardDevice.ChangeFocus(System.Windows.DependencyObject focus, int timestamp) + 0x63e bytes 
  PresentationCore.dll!System.Windows.Input.KeyboardDevice.TryChangeFocus(System.Windows.DependencyObject newFocus, System.Windows.Input.IKeyboardInputProvider keyboardInputProvider, bool askOld, bool askNew, bool forceToNullIfFailed) + 0x12b bytes 
  PresentationCore.dll!System.Windows.Input.KeyboardDevice.Focus(System.Windows.DependencyObject focus, bool askOld, bool askNew) + 0xc2 bytes 
  PresentationCore.dll!System.Windows.Input.KeyboardDevice.Focus(System.Windows.IInputElement element) + 0x1a bytes 
  PresentationCore.dll!System.Windows.UIElement.Focus() + 0x1a bytes 
  Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.RadTreeViewItem.OnHeaderMouseLeftButtonDown(object sender = {System.Windows.Controls.Grid}, System.Windows.Input.MouseButtonEventArgs e = {System.Windows.Input.MouseButtonEventArgs}) + 0x7f bytes 
  PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget) + 0x31 bytes 
  PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) + 0x27 bytes 
  PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs) + 0x3e bytes 
  PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source = {System.Windows.Controls.Grid}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}, bool reRaised = true) + 0x1bf bytes 
  PresentationCore.dll!System.Windows.UIElement.ReRaiseEventAs(System.Windows.DependencyObject sender = {System.Windows.Controls.Grid}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}, System.Windows.RoutedEvent newEvent) + 0x10a bytes 
  PresentationCore.dll!System.Windows.UIElement.CrackMouseButtonEventAndReRaiseEvent(System.Windows.DependencyObject sender, System.Windows.Input.MouseButtonEventArgs e) + 0x2e bytes 
  PresentationCore.dll!System.Windows.UIElement.OnMouseDownThunk(object sender, System.Windows.Input.MouseButtonEventArgs e) + 0xde bytes 
  PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget) + 0x31 bytes 
  PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) + 0x27 bytes 
  PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs) + 0x3e bytes 
  PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source = {System.Windows.Controls.TextBlock}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}, bool reRaised = false) + 0x1bf bytes 
  PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender = {System.Windows.Controls.TextBlock}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}) + 0x79 bytes 
  PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}, bool trusted) + 0x35 bytes 
  PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea() + 0x311 bytes 
  PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input) + 0x42 bytes 
  PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport) + 0x62 bytes 
  PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode mode, int timestamp, System.Windows.Input.RawMouseActions actions, int x, int y, int wheel) + 0x2e2 bytes 
  PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.FilterMessage(System.IntPtr hwnd = 591552, int msg = 513, System.IntPtr wParam = 1, System.IntPtr lParam = 589869, ref bool handled = false) + 0x4e1 bytes 
  PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd = 591552, int msg = 513, System.IntPtr wParam = 1, System.IntPtr lParam = 589869, ref bool handled = false) + 0x75 bytes 
  WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd = 591552, int msg = 513, System.IntPtr wParam = 1, System.IntPtr lParam = 589869, ref bool handled = false) + 0xbe bytes 
  WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) + 0x7a bytes 
  WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback = {Method = {System.Object DispatcherCallbackOperation(System.Object)}}, object args = {MS.Win32.HwndSubclass.DispatcherOperationCallbackParameter}, bool isSingleParameter = true) + 0x8a bytes 
  WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate callback, object args, bool isSingleParameter, System.Delegate catchHandler = null) + 0x4a bytes 
  WindowsBase.dll!System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate callback, object args, bool isSingleParameter, System.Delegate catchHandler) + 0x44 bytes 
  WindowsBase.dll!System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, bool isSingleParameter) + 0x91 bytes 
  WindowsBase.dll!System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority priority, System.Delegate method, object arg) + 0x40 bytes 
  WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd = 591552, int msg = 513, System.IntPtr wParam = 1, System.IntPtr lParam = 589869) + 0xdc bytes 
  [Native to Managed Transition] 
  [Managed to Native Transition] 
> System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID, int reason = -1, int pvLoopData = 0) Line 2106 + 0x8 bytes C#
  System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) Line 3377 + 0x1b bytes C#
  System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) Line 3261 + 0xa bytes C#
  System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) Line 1466 C#
  WinAppCS.exe!WinAppCS.Program.Main() Line 18 + 0x1d bytes C#
  [Native to Managed Transition] 
  [Managed to Native Transition] 
  mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) Line 931 + 0x1f bytes C#
  Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x2b bytes 
  mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) Line 61 + 0xffffffe3 bytes C#
  mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 355 + 0xd bytes C#
  mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() Line 88 + 0xffffffe4 bytes C#

3 Answers, 1 is accepted

Sort by
0
prakash
Top achievements
Rank 1
answered on 19 Jun 2009, 07:03 AM
I got a workaround for the above problem by creating a new Application object in the Main().

System.Windows.

Application app = new System.Windows.Application();

I am not sure whether it was the corret way of to solve the problem :(

 

0
Bobi
Telerik team
answered on 19 Jun 2009, 07:45 AM
Hello prakash,

We are aware of this issue. The problem is already fixed and the change will be reflected in the next Q2 release which is scheduled for the beginning of July.

As a workaround for now creating an instance of System.Windows.Application() is the way you can prevent this exception happens.

Kind regards,
Boryana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
prakash
Top achievements
Rank 1
answered on 19 Jun 2009, 10:23 AM
thank you for your reply Boryana. I will use with the workaround until the next release.

-
prakash
Tags
TreeView
Asked by
prakash
Top achievements
Rank 1
Answers by
prakash
Top achievements
Rank 1
Bobi
Telerik team
Share this question
or