Skip to content

Commit 395c0dd

Browse files
authored
Merge pull request #3424 from rubberduck-vba/SaferComWrappers
Prevents iterating VBComponents collection on a locked project.
2 parents 3da8162 + 67026cc commit 395c0dd

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Rubberduck.VBEEditor/SafeComWrappers/VBA/VBComponents.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ public override int GetHashCode()
9999

100100
public void ImportSourceFile(string path)
101101
{
102+
if (IsWrappingNullReference) { return; }
103+
102104
var ext = Path.GetExtension(path);
103105
var name = Path.GetFileNameWithoutExtension(path);
104106
if (!File.Exists(path))
@@ -152,6 +154,8 @@ public void ImportSourceFile(string path)
152154

153155
public void RemoveSafely(IVBComponent component)
154156
{
157+
if (component.IsWrappingNullReference) { return; }
158+
155159
switch (component.Type)
156160
{
157161
case ComponentType.ClassModule:
@@ -174,7 +178,7 @@ private static void AttachEvents(VB.VBComponents components)
174178
{
175179
lock (Locker)
176180
{
177-
if (_components == null)
181+
if (_components == null && components != null)
178182
{
179183
_components = components;
180184
_componentAdded = OnComponentAdded;

Rubberduck.VBEEditor/SafeComWrappers/VBA/VBProject.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public IReferences References
6060

6161
public IVBComponents VBComponents
6262
{
63-
get { return new VBComponents(IsWrappingNullReference ? null : Target.VBComponents); }
63+
get { return new VBComponents(IsWrappingNullReference || Protection == ProjectProtection.Locked ? null : Target.VBComponents); }
6464
}
6565

6666
public ProjectProtection Protection
@@ -232,4 +232,4 @@ public string ProjectDisplayName
232232
}
233233
}
234234
}
235-
}
235+
}

0 commit comments

Comments
 (0)