Skip to content

Commit 19d0f43

Browse files
committed
avoid working with a null wrapper when importing source file, ref.#2386
1 parent f270582 commit 19d0f43

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Rubberduck.VBEEditor/SafeComWrappers/VBA/VBComponents.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,17 @@ public void ImportSourceFile(string path)
116116
if (ext == ComponentTypeExtensions.DocClassExtension)
117117
{
118118
var component = this[name];
119+
if (component.IsWrappingNullReference)
120+
{
121+
throw new InvalidOperationException(string.Format("Could not find document component named '{0}'.", name));
122+
}
119123
component.CodeModule.Clear();
120124
component.CodeModule.AddFromString(codeString);
121125
}
122126
else if (ext == ComponentTypeExtensions.FormExtension)
123127
{
124-
IVBComponent component;
125-
try
126-
{
127-
component = this[name];
128-
}
129-
catch
128+
var component = this[name];
129+
if (component.IsWrappingNullReference)
130130
{
131131
component = Add(ComponentType.UserForm);
132132
component.Properties["Caption"].Value = name;

0 commit comments

Comments
 (0)