Skip to content

Commit c764b1e

Browse files
authored
Merge pull request #1992 from Hosch250/FixTestMethodCommands
Catch COM exception when accessing code module for removed component.
2 parents 13d2ce7 + 97689ee commit c764b1e

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

RetailCoder.VBE/UI/Command/AddTestMethodCommand.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,17 @@ protected override bool CanExecuteImpl(object parameter)
3434
d.DeclarationType == DeclarationType.ProceduralModule &&
3535
d.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule));
3636

37-
// the code modules consistently match correctly, but the components don't
38-
return testModules.Any(a => a.QualifiedName.QualifiedModuleName.Component.CodeModule == _vbe.SelectedVBComponent.CodeModule);
37+
try
38+
{
39+
// the code modules consistently match correctly, but the components don't
40+
return testModules.Any(a =>
41+
a.QualifiedName.QualifiedModuleName.Component.CodeModule ==
42+
_vbe.SelectedVBComponent.CodeModule);
43+
}
44+
catch (COMException)
45+
{
46+
return false;
47+
}
3948
}
4049

4150
protected override void ExecuteImpl(object parameter)

RetailCoder.VBE/UI/Command/AddTestMethodExpectedErrorCommand.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,17 @@ protected override bool CanExecuteImpl(object parameter)
3434
d.DeclarationType == DeclarationType.ProceduralModule &&
3535
d.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule));
3636

37-
// the code modules consistently match correctly, but the components don't
38-
return testModules.Any(a => a.QualifiedName.QualifiedModuleName.Component.CodeModule == _vbe.SelectedVBComponent.CodeModule);
37+
try
38+
{
39+
// the code modules consistently match correctly, but the components don't
40+
return testModules.Any(a =>
41+
a.QualifiedName.QualifiedModuleName.Component.CodeModule ==
42+
_vbe.SelectedVBComponent.CodeModule);
43+
}
44+
catch (COMException)
45+
{
46+
return false;
47+
}
3948
}
4049

4150
protected override void ExecuteImpl(object parameter)

0 commit comments

Comments
 (0)