ApplicationMenu: Unhandled exception while handling keyboard input

Ribbon for WPF Forum

Posted 10 years ago by Jiping Zhu (James)
Version: 13.2.0591
Platform: .NET 4.5
Environment: Windows 7 (64-bit)
Avatar

Hello there,

We experience an unhandled NullReferenceException thrown by OnTextInput method of ApplicationMenu class.

 

Symptoms:

An application crash occurs when a user opens Application Menu via mouse click, and attempt to click a menu item access key. The issue is hidden if the user opens the Application Menu via alt + F. Note that we do not use FooterButtons in our application menu.

 

Exception Details:

Tracings show that the exception was thrown in ApplicationMenu.OnTextInput() method, where it attempted to iterate through FooterButtons property's private field of type RibbonControlCollection.

From DotPeek, we could see that the private field is lazy initialized by FooterButtons property's get method, and thus the private field is null if the property get method was never called.

My guess is that the ApplicationMenu tries matching the text input to footer buttons' key access texts, but the code seems missing a null reference check on FooterButtons property's private field.

 

Workaround:

So far we have adopted a workaround by explicitly calling ApplicationMenu.FooterButtons get method in code-behind to avoid the issue.

However, I do wish that the issue be fixed in the next release, as the workaround looks ugly and confusing.

 


Code Snippet from DotPeek:

In ApplicationMenu class,

protected override void OnTextInput(TextCompositionEventArgs e)
{
...
...
...

    foreach (UIElement uiElement in (Collection<UIElement>) this.#7ob)
    {
        if (uiElement != null && uiElement.IsEnabled && KeyTipService.GetKeyTipAccessText((DependencyObject) uiElement) == keyTipAccessText)
        {
            IKeyTipTarget keyTipTarget = uiElement as IKeyTipTarget;
            if (keyTipTarget != null)
            {
                e.Handled = keyTipTarget.NotifyKeyTipAccessed(keyTipAccessText);
                break;
            }
        }
    }
}

 

this.#7ob (which is lazy initialized by FooterButtons), was null at the time the crash occurred.

Comments (1)

Answer - Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Thank you for reporting this.  We've fixed it for the upcoming maintenance release.


Actipro Software Support

The latest build of this product (v24.1.1) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.