diff --git a/src/dotnetCampus.Ipc.Analyzers/SourceGenerators/Models/SourceTextBuilder.cs b/src/dotnetCampus.Ipc.Analyzers/SourceGenerators/Models/SourceTextBuilder.cs index 13023e1f..2dd12938 100644 --- a/src/dotnetCampus.Ipc.Analyzers/SourceGenerators/Models/SourceTextBuilder.cs +++ b/src/dotnetCampus.Ipc.Analyzers/SourceGenerators/Models/SourceTextBuilder.cs @@ -34,7 +34,11 @@ public SourceTextBuilder AddUsingForTypes(params ITypeSymbol[] typeSymbols) public string SimplifyNameByAddUsing(ITypeSymbol typeSymbol) { var originalName = typeSymbol.ToString(); - var @namespace = typeSymbol.ContainingNamespace.ToString(); + var @namespace = typeSymbol.ContainingNamespace?.ToString(); + if (@namespace == null) + { + return originalName; + } if (originalName.StartsWith(@namespace, StringComparison.Ordinal)) { // 常规类型,“命名空间.类名”型。