You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: NullReferenceException in ResidesInNamespace when using Types(true) #492
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
usingSystem.Linq;usingArchUnitNET.Loader;vararchitecture=newArchLoader().LoadAssemblies(typeof(System.DateTime).Assembly)// System.Private.CoreLib.Build();// Works fineTypes().That().ResideInNamespace("System").GetObjects(architecture).Count();// Throws NRETypes(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.
Hi @AvremelM, thanks for opening the issue. Option 1 makes more sense here. Function pointer types are mostly generated as dependencies of other types, so ignoring them could leave the dependencies of those other types incomplete.
Hi @alexanderlinne, I'd like to work on this, going with option 1 as you suggested (null-guarding the namespace extensions). I'll also make the failure descriptions of the ResideInNamespace / NotResideInNamespace conditions handle a missing namespace, since they dereference it too, and add regression tests using the System.Private.CoreLib repro. I should have a PR up in the next few days.
Activity
alexanderlinne commentedon Sep 11, 2026
Hi @AvremelM, thanks for opening the issue. Option 1 makes more sense here. Function pointer types are mostly generated as dependencies of other types, so ignoring them could leave the dependencies of those other types incomplete.
iamAdarshh commentedon Sep 28, 2026
Hi @alexanderlinne, I'd like to work on this, going with option 1 as you suggested (null-guarding the namespace extensions). I'll also make the failure descriptions of the ResideInNamespace / NotResideInNamespace conditions handle a missing namespace, since they dereference it too, and add regression tests using the System.Private.CoreLib repro. I should have a PR up in the next few days.
fix: handle types without a namespace or assembly in reside-in checks
fix: handle types without a namespace or assembly in reside-in checks
fix: handle types without a namespace or assembly in reside-in checks