From 154d3d03dd40b825aeb6e434d71b50a2fcf538a0 Mon Sep 17 00:00:00 2001 From: Jason Ginchereau Date: Tue, 16 Apr 2024 06:39:17 -1000 Subject: [PATCH] Fix NRE in source generator for methods with arrays (#278) --- src/NodeApi.Generator/SourceGenerator.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/NodeApi.Generator/SourceGenerator.cs b/src/NodeApi.Generator/SourceGenerator.cs index 5dafdeff..181302f6 100644 --- a/src/NodeApi.Generator/SourceGenerator.cs +++ b/src/NodeApi.Generator/SourceGenerator.cs @@ -49,12 +49,15 @@ public enum DiagnosticId public static string GetNamespace(ISymbol symbol) { string ns = string.Empty; + + // ContainingNamespace may be null for constructed types like arrays. for (INamespaceSymbol s = symbol.ContainingNamespace; - !s.IsGlobalNamespace; + s?.IsGlobalNamespace == false; s = s.ContainingNamespace) { ns = s.Name + (ns.Length > 0 ? "." + ns : string.Empty); } + return ns; }