From 0c76562be327e1a728c789af2f9beaefef76950d Mon Sep 17 00:00:00 2001 From: thewrz Date: Tue, 6 Oct 2026 16:04:56 -0700 Subject: [PATCH] fix(revit): scope the PushButtonData release with a using on the IDisposable view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The finally-block dispose (#711) satisfied cs/local-not-disposed but tripped cs/missed-using-statement (code-quality finding #7). A `using` on `buttonData as IDisposable` keeps one code path for all legs — null, so a no-op, on Revit 2024 where the type is not disposable; a release at scope exit on Revit 2025+ — and is the form both queries accept. Co-Authored-By: Claude Fable 5.1 --- revit-addin/App.cs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/revit-addin/App.cs b/revit-addin/App.cs index eea5a390..3faff471 100644 --- a/revit-addin/App.cs +++ b/revit-addin/App.cs @@ -36,19 +36,14 @@ public Result OnStartup(UIControlledApplication application) $"Calls SpecR at the URL in the {SpecRClient.BaseUrlEnvVar} environment " + $"variable (default {SpecRClient.DefaultBaseUrl}).", }; - try - { - panel.AddItem(buttonData); - return Result.Succeeded; - } - finally - { - // From Revit 2025 the ribbon data classes are disposable API - // wrappers (Revit 2024's are not); the panel has copied what it - // needs in AddItem, so release the data object either way without - // a per-version #if (CodeQL cs/local-not-disposed). - (buttonData as IDisposable)?.Dispose(); - } + // From Revit 2025 the ribbon data classes are disposable API wrappers + // (Revit 2024's are not): release the data object at the end of this + // scope on the legs where it is one, with a single code path for all + // of them. The panel copies what it needs in AddItem. + using var releaseButtonData = buttonData as IDisposable; + + panel.AddItem(buttonData); + return Result.Succeeded; } catch (Exception ex) when (ex is Autodesk.Revit.Exceptions.ApplicationException || ex is InvalidOperationException)