Description
Namespace predicates (ResideInNamespace, ResideInNamespaceMatching) throw a NullReferenceException when the architecture includes function-pointer types, because IType.Namespace is null for them and the extension dereferences it without a guard.
Minimal Working Example
using System.Linq;
using ArchUnitNET.Loader;
var architecture = new ArchLoader()
.LoadAssemblies(typeof(System.DateTime).Assembly) // System.Private.CoreLib
.Build();
// Works fine
Types().That().ResideInNamespace("System").GetObjects(architecture).Count();
// Throws NRE
Types(true).That().ResideInNamespace("System").GetObjects(architecture).Count();
Expected Behavior
Types with null namespaces would not match any namespace predicate.
Actual Behavior
Types with null namespaces cause a NullReferenceException
Stack
Object reference not set to an instance of an object.
at ArchUnitNET.Domain.Extensions.NamingExtensions.FullNameEquals(IHasName cls, String fullName)
at ArchUnitNET.Domain.Extensions.TypeExtensions.ResidesInNamespace(IType e, String fullName)
at ArchUnitNET.Fluent.Syntax.Elements.Types.TypePredicatesDefinition`1.<>c__DisplayClass9_0.<ResideInNamespace>b__0(T type)
at System.Linq.Enumerable.ArrayWhereIterator`1.GetCount(Boolean onlyIfCheap, ReadOnlySpan`1 source, Func`2 predicate)
at System.Linq.Enumerable.ListWhereIterator`1.GetCount(Boolean onlyIfCheap)
ArchUnitNET Version
0.13.4
.NET Version
.NET 9 (or any CoreCLR version)
Additional Context
32 types with a null Namespace, all Cecil FunctionPointerType, e.g.
method System.Object *(System.IntPtr,System.Object)
method System.Boolean *(System.Object)
They appear only in ReferencedTypes (0 in Types).
Suggested fix:
- Option 1: Null-guard the namespace extensions, e.g. return e.Namespace?.FullNameMatches(pattern) ?? false; (same for ResidesInNamespace).
- Option 2: Skip FunctionPointerType when building the type set — ArchBuilder already filters
Microsoft.CodeAnalysis.EmbeddedAttribute, System.Runtime.CompilerServices.Nullable(Context)Attribute and Coverlet*.
I'm more than happy to open a PR for either approach (or any other solution) if that helps.
Description
Namespace predicates (
ResideInNamespace,ResideInNamespaceMatching) throw a NullReferenceException when the architecture includes function-pointer types, because IType.Namespace is null for them and the extension dereferences it without a guard.Minimal Working Example
Expected Behavior
Types with null namespaces would not match any namespace predicate.
Actual Behavior
Types with null namespaces cause a NullReferenceException
Stack
ArchUnitNET Version
0.13.4
.NET Version
.NET 9 (or any CoreCLR version)
Additional Context
32 types with a null Namespace, all Cecil FunctionPointerType, e.g.
method System.Object *(System.IntPtr,System.Object)method System.Boolean *(System.Object)They appear only in ReferencedTypes (0 in Types).
Suggested fix:
Microsoft.CodeAnalysis.EmbeddedAttribute,System.Runtime.CompilerServices.Nullable(Context)AttributeandCoverlet*.I'm more than happy to open a PR for either approach (or any other solution) if that helps.