Bug Report T521130
Visible to All Users

NullReferenceException is thrown in the BarSubItemLink.CanOpenMenuCore property in certain scenarios

created 8 years ago

We are getting this error periodically when working within a context menu in our application. Is this a known issue, any idea about how to fix? Thanks!

System.NullReferenceException: Object reference not set to an instance of an object.
   at DevExpress.Xpf.Bars.BarSubItemLink.get_CanOpenMenuCore()
   at DevExpress.Xpf.Bars.BarSubItemLink.get_CanOpenMenu()
   at DevExpress.Xpf.Bars.BarSubItemLinkControl.GetCanOpenMenu()
   at DevExpress.Xpf.Bars.BarSubItemLinkControl.OnIsPressedCoerce(Object value)
   at DevExpress.Xpf.Bars.BarItemLinkControl.<.cctor>b__8(DependencyObject d, Object e)
   at System.Windows.DependencyObject.ProcessCoerceValue(DependencyProperty dp, PropertyMetadata metadata, EntryIndex& entryIndex, Int32& targetIndex, EffectiveValueEntry& newEntry, EffectiveValueEntry& oldEntry, Object& oldValue, Object baseValue, Object controlValue, CoerceValueCallback coerceValueCallback, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, Boolean skipBaseValueChecks)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at DevExpress.Xpf.Bars.BarItemLinkControl.set_IsPressed(Boolean value)
   at DevExpress.Xpf.Bars.BarSubItemLinkControl.ShowPopup()
   at DevExpress.Xpf.Bars.PopupMenuManager.ShowPopup(BarPopupBase popup, Action showPopupAction)
   at DevExpress.Xpf.Bars.PopupMenuManager.OnShowPopupTimerTick(Object sender, EventArgs e)
   at System.Windows.Threading.DispatcherTimer.FireTick(Object unused)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Window.ShowHelper(Object booleanBox)
   at System.Windows.Window.ShowDialog()
   at Summit.Exchange.Client.App.Application_Startup(Object sender, StartupEventArgs e) in C:\TFS\Summit.Products\Development\Summit.Exchange\Summit.Exchange.Client\App.xaml.cs:line 108
   at System.Windows.Application.OnStartup(StartupEventArgs e)
   at System.Windows.Application.<.ctor>b__1_0(Object unused)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at Summit.Exchange.Client.App.Main()
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Show previous comments (2)
DevExpress Support Team 8 years ago

    Hi Paul,

    I have not managed to find fixed issues with a similar callstack. Would you please clarify what issue you mean?

    Nevertheless, our developers reviewed your callstack, and they are ready to add the required check to the CanOpenMenuCore property. Since the production cycle for the version you specified (15.1) is ended and you cannot upgrade at the moment, I would like to provide you with an immediate workaround. The workaround is to replace BarSubItemLink objects in your application with a BarSubItemLinkEx descendant from my sample. If you don't create links manually, it will be sufficient to copy the descendant to your project and register it:

    C#
    static MainWindow() { BarItemLinkCreator.Default.RegisterObject(typeof(BarSubItem), typeof(BarSubItemLink), x => new BarSubItemLinkEx()); }

    Thanks

      I've tried your approach and I got a different exception shown below. The bar items are defined in a resource dictionary. If I choose to set the property 'CheckBarItemNames' to false I am still able to reproduce the exception. Thank you for your efforts. Is there something else I could try?

      Exception thrown: 'System.Windows.Markup.XamlParseException' in PresentationFramework.dll

      Additional information: BarItemLink refers to unsupported BarItem. Cannot assign BarItemLink with BarItem by name: "itemInboundAddSender".

      To suppress this exception, set BarManager.CheckBarItemNames static property to False

      DevExpress Support Team 8 years ago

        Hi again,

        This exception may occur if you did not replace BarSubItemLink with BarSubItemLinkEx in your code. Since the workaround is implemented in the BarSubItemLink class descendant, it will be necessary to modify your implementation in the following manner:

        XAML
        <dxb:ToolBarControl> <dxb:BarSubItem Content="BarSubItem" Name="item"> <dxb:BarButtonItem Content="BarButtonItem"/> </dxb:BarSubItem> <!--<dxb:BarSubItemLink BarItemName="item"/>--> <local:BarSubItemLinkEx BarItemName="item"/> </dxb:ToolBarControl>

        local in the code snippet above is a namespace where the BarSubItemLinkEx class is declared.

        Answers approved by DevExpress Support

        created 8 years ago

        We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

        Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.