Skip to content

Don't share members between types with the same full name - #529

Draft
alexanderlinne wants to merge 1 commit into
fix/frozen-rule-storesfrom
fix/duplicate-type-member-cache
Draft

alexanderlinne wants to merge 1 commit into
fix/frozen-rule-storesfrom
fix/duplicate-type-member-cache

Conversation

@alexanderlinne

@alexanderlinne alexanderlinne commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Why

ArchUnitNET loads types with the same full name from different assemblies as separate types: DomainResolver caches types by assembly-qualified name. Methods and fields, however, were cached by full name only. The second Ns.Dup therefore received the first Ns.Dup's members: its .ctor() reported the other type as DeclaringType and the other assembly as Assembly. On top of that, MethodMember, FieldMember and PropertyMember compared equal by full name alone, so rule evaluation couldn't tell such members apart either. A member rule failing for both types reported one violation.

#531 needs this to tell frozen members apart by assembly, not only types. This PR doesn't use anything from #528; it is based on it only so that #531 contains both.

What changes

Member cache. DomainResolver caches methods and fields per declaring type's assembly (Assembly.CreateQualifiedName(declaringType.Assembly.FullName, memberFullName)), the same key scheme as types.

Member equality. MethodMember, FieldMember and PropertyMember implement Equals and GetHashCode on AssemblyQualifiedName, which they already had, like Type does.

Tests. The DuplicateClass fixtures in both duplicate test assemblies gain a field, so both the method and the field cache are covered. ArchLoaderTests checks that each duplicate type owns its own constructor and field, and that the four members are distinct.

Behaviour change

Members of types that share a full name across assemblies now report the correct declaring type and assembly, and are no longer equal to each other.

DomainResolver cached methods and fields by their full name, while
types are cached by assembly-qualified name. With the same full name in
two assemblies, the second type received the first type's members, so
they reported the wrong declaring type and assembly. Members also
compared equal by full name alone, so rule evaluation could not tell
them apart either.

Cache members per declaring type's assembly, and compare method, field
and property members by their assembly-qualified name, like types.

The duplicate test fixtures gain a field so that both caches are
covered.

Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 87.04%. Comparing base (983b9b5) to head (da85f89).

Files with missing lines Patch % Lines
ArchUnitNET/Loader/DomainResolver.cs 92.85% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@                    Coverage Diff                     @@
##           fix/frozen-rule-stores     #529      +/-   ##
==========================================================
+ Coverage                   87.02%   87.04%   +0.01%     
==========================================================
  Files                         261      261              
  Lines                       12691    12694       +3     
  Branches                     1232     1233       +1     
==========================================================
+ Hits                        11044    11049       +5     
+ Misses                       1300     1297       -3     
- Partials                      347      348       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants