From 290e4420d8608708691268e22688b8b81e259455 Mon Sep 17 00:00:00 2001 From: Maarten van Stam Date: Fri, 6 Mar 2015 14:26:45 +0100 Subject: [PATCH] Update RibbonFactory.cs It appears that control can have an empty Context and causing GetVisible to crash hard ... I assume under the hood control.Context is used but I don't see where. (Added also the return line to make it easier to get the return value) The context check should probably be added to -all- control using methods but so far I just ran into issues on GetVisible and GetPressed. Have only changed GetVisible and GetPressed to get your feedback. --- src/VSTOContrib.Core/RibbonFactory/RibbonFactory.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/VSTOContrib.Core/RibbonFactory/RibbonFactory.cs b/src/VSTOContrib.Core/RibbonFactory/RibbonFactory.cs index a36d85c..44d58dd 100644 --- a/src/VSTOContrib.Core/RibbonFactory/RibbonFactory.cs +++ b/src/VSTOContrib.Core/RibbonFactory/RibbonFactory.cs @@ -236,7 +236,10 @@ public string GetSuperTip(IRibbonControl control) /// public bool GetVisible(IRibbonControl control) { - return (bool)ribbonFactoryController.InvokeGet(control, () => GetVisible(null)); + if (control == null || control.Context == null) return false; + + object result = ribbonFactoryController.InvokeGet(control, () => GetVisible(null)); + return (bool) result; } /// @@ -370,7 +373,10 @@ public string GetTitle(IRibbonControl control) /// public bool GetPressed(IRibbonControl control) { - return (bool)ribbonFactoryController.InvokeGet(control, () => GetPressed(null)); + if (control == null || control.Context == null) return false; + + object result = ribbonFactoryController.InvokeGet(control, () => GetPressed(null)); + return (bool) result; } ///