Repository navigation
Fix COM ownership and host lookup issues found in #99 - #100
Merged
Merged
Conversation
- Release the AddIn RCW only in Connect (AddInManager no longer releases it) - Dispose the previous OfficeApplicationHelper when the host application is re-initialized - ComTools: continue with the ROT search if GetActiveObject fails; skip faulty ROT entries - OfficeApplicationHelper: fix inverted condition in GetCheckedVbProject - Add unit tests for the project lookup condition and the unregistered ProgID case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #99: fixes the four findings listed there under "Not changed (found on the way)".
Changes
Connectowns the RCW (it receives it inOnConnection) and releases it exactly once.AddInManager.DisposeUnmanagedResourcesonly drops its reference. Before, the secondReleaseComObjectthrewInvalidComObjectExceptioninsideConnect.Dispose(true), skippingGC.Collect,_disposed = trueand theDisposedevent.AddInBridgeHostApplicationInitialized: the previousOfficeApplicationHelperis disposed after the new one was created (both may wrap the same application RCW, so the reference count must not drop to 0 in between).ComTools.GetOfficeComObjectByProgIDAndVBE:Marshal.GetActiveObjectfailures are logged and the lookup continues with the ROT search. A faulty ROT entry no longer aborts the enumeration (try/catch per moniker).GetTypeForComObjectreturnsnullfor an unregistered ProgID instead of throwing.OfficeApplicationHelper.GetCheckedVbProject: the condition was inverted (IsNullOrEmpty && !match, i.e. the project lookup never took effect). NowIsProjectLookupRequired=!IsNullOrEmpty && !match. Note: this makes the lookup active for non-Access hosts for the first time; failures still fall back toActiveVBProjectvia the existing catch.Tests
HostLookupTests):IsProjectLookupRequiredcases;GetOfficeComObjectByProgIDAndVBEwith a ProgID that is not registered returnsnullinstead of throwing. Test project got a reference toMicrosoft.Vbe.Interop.source\AccessCodeLib.AccUnit.slnandvbe-add-In\AccessCodeLib.AccUnit.VbeAddIn.sln: passed. NUnit tests not run locally (CI).access-add-in/lib, no COM registration, own visible instance only):null, Access process count unchanged (no new instance).GetOfficeComObjectByProgIDAndVBEfinds the correct host.GetActiveObjectthrowing (covered by the unit test only); a real VBE whoseFileNameis missing in the ROT (Access registers the moniker under the path it was opened with).Not changed
OfficeApplicationHelper.FindVbProjectEqualsFullNameusesFirst()and throws instead of returningnullwhen no project matches (caught inGetCheckedVbProject).