diff --git a/ICSharpCode.Decompiler/TypeSystem/IEntity.cs b/ICSharpCode.Decompiler/TypeSystem/IEntity.cs
index 92452c64a..c6c9c9f3a 100644
--- a/ICSharpCode.Decompiler/TypeSystem/IEntity.cs
+++ b/ICSharpCode.Decompiler/TypeSystem/IEntity.cs
@@ -58,8 +58,9 @@ namespace ICSharpCode.Decompiler.TypeSystem
///
/// The module in which this entity is defined.
+ /// May return null, if the IEntity was not created from a module.
///
- IModule ParentModule { get; }
+ IModule? ParentModule { get; }
///
/// Gets the attributes on this entity.
diff --git a/ILSpy/Commands/ScopeSearchToAssembly.cs b/ILSpy/Commands/ScopeSearchToAssembly.cs
index 89512a2c9..e2caeff7c 100644
--- a/ILSpy/Commands/ScopeSearchToAssembly.cs
+++ b/ILSpy/Commands/ScopeSearchToAssembly.cs
@@ -15,6 +15,8 @@
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
+#nullable enable
+
using System;
using ICSharpCode.Decompiler.TypeSystem;
@@ -28,7 +30,8 @@ namespace ICSharpCode.ILSpy
{
public void Execute(TextViewContext context)
{
- string asmName = GetAssembly(context);
+ // asmName cannot be null here, because Execute is only called if IsEnabled/IsVisible return true.
+ string asmName = GetAssembly(context)!;
string searchTerm = MainWindow.Instance.SearchPane.SearchTerm;
string[] args = NativeMethods.CommandLineToArgumentArray(searchTerm);
bool replaced = false;
@@ -62,10 +65,10 @@ namespace ICSharpCode.ILSpy
return GetAssembly(context) != null;
}
- string GetAssembly(TextViewContext context)
+ string? GetAssembly(TextViewContext context)
{
if (context.Reference?.Reference is IEntity entity)
- return entity.ParentModule.AssemblyName;
+ return entity.ParentModule?.AssemblyName;
if (context.SelectedTreeNodes?.Length != 1)
return null;
switch (context.SelectedTreeNodes[0])
@@ -73,7 +76,7 @@ namespace ICSharpCode.ILSpy
case AssemblyTreeNode tn:
return tn.LoadedAssembly.ShortName;
case IMemberTreeNode member:
- return member.Member.ParentModule.AssemblyName;
+ return member.Member?.ParentModule?.AssemblyName;
default:
return null;
}
diff --git a/ILSpy/TreeNodes/IMemberTreeNode.cs b/ILSpy/TreeNodes/IMemberTreeNode.cs
index 2aa0d8619..81dbde36f 100644
--- a/ILSpy/TreeNodes/IMemberTreeNode.cs
+++ b/ILSpy/TreeNodes/IMemberTreeNode.cs
@@ -15,6 +15,7 @@
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
+#nullable enable
using ICSharpCode.Decompiler.TypeSystem;
@@ -31,6 +32,6 @@ namespace ICSharpCode.ILSpy.TreeNodes
/// Returns the entity that is represented by this tree node.
/// May return null, if the member cannot be resolved.
///
- IEntity Member { get; }
+ IEntity? Member { get; }
}
}