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
Assert.Fail failed. "Types that reside in namespace with full name "ClassLibrary1" should only depend on Types that reside in assembly with full name "System"" failed:
ClassLibrary1.Class1 does depend on System.Object and System.Runtime.CompilerServices.NullableAttribute and ClassLibrary1.Class1
Note that it also complains about system types. When I add .Or().ResideInNamespace("ClassLibrary1"), the test succeeds.
Is it possible to only complain about types that real errors instead of complaining about all references? Or am I missing something?
I've now been investigating this and found the following:
If you want to match Types from System Namespace you would need to do Types().That().ResideInNamespace("^System.*", true). On the one hand, these types are distributed among multiple namespaces and assemblies. On the other hand, ResideInAssembly currently matches the fully qualified name of the assembly, which not only includes it's name. We plan to change this in the future, I've created ResideInAssembly should not match the fully qualified name #290 to track this separately.
That the type itself is included does not make much sense in my opinion. Given that usually most types have some dependency on themselves I'm preparing a patch that filters these dependencies.
That is System types are listed in the error is actually a bug in how the errors are formatted. I'm also working on a patch for this.
I will link this issue as soon as the patch is ready.
Hi @alexanderlinne are you still intending to release a patch which stops System.* types from being reported in the errors? I've just started using ArchUnitNet and I find this to be pretty annoying as I wade through the errors trying to understand what's wrong with either my code being tested or the tests I've written :)
In fact can I go a bit further and enquire why System types are not fully excluded from the framework? Eg, filter them out when gathering types from an assembly & from type dependencies etc.
In fact can I go a bit further and enquire why System types are not fully excluded from the framework? Eg, filter them out when gathering types from an assembly & from type dependencies etc.
System types are not excluded simply because there are use-cases where users want to assert that their types or methods do not depend on specific types from the System namespace.
Hi @alexanderlinne are you still intending to release a patch which stops System.* types from being reported in the errors? I've just started using ArchUnitNet and I find this to be pretty annoying as I wade through the errors trying to understand what's wrong with either my code being tested or the tests I've written :)
I still would like to improve this, if possible. I'm still working on improving the test coverage of and refactoring the fluent syntax, such that we can change how types are loaded and clearly see how this would affect the existing fluent syntax methods.
What will probably not happen is that System types won't appear in the error message at all. This affects e.g. OnlyDependOn because you'd often have to include System.* there. What I've already experimented with is excluding self-references and System.Object from the dependencies, both may be feasible but could also have unintended side effects.
Is there a specific example and error that does not make sense to you?
(I should say that ResideInAssemblyNamed is an extension method which uses ResideInAssemblyMatching and ResideInOrBelowNamespace uses ResideInNamespaceMatching with a regex to match System and System.*)
I'll get a description like this:
Foo.Bar.Apis.Controllers.FooBarController does depend on System.Web.Http.ApiController and System.Web.Http.Controllers.IHttpController and System.IDisposable and Foo.Bar.Services.Interface.Database.IContextFactory and System.Runtime.CompilerServices.AsyncStateMachineAttribute and System.Diagnostics.DebuggerStepThroughAttribute and System.Web.Http.AuthorizeAttribute and System.Web.Http.HttpGetAttribute and System.Web.Http.RouteAttribute and System.Threading.Tasks.Task`1 and System.Int32 and System.Object and Foo.Bar.Services.Interface.Database.IContext`1 and System.Type and System.Linq.Expressions.Expression and System.Reflection.MethodBase and System.Reflection.FieldInfo and System.Linq.Queryable and System.Runtime.CompilerServices.TaskAwaiter`1 and System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 and System.Nullable`1 and System.Linq.Expressions.ParameterExpression and System.Web.Http.IHttpActionResult and System.Boolean and System.Exception and System.Reflection.MethodInfo and System.Web.Http.HttpPostAttribute and System.Threading.Tasks.Task and System.Runtime.CompilerServices.TaskAwaiter and System.Web.Http.HttpPutAttribute and System.Web.Http.HttpPatchAttribute and System.Web.Http.FromUriAttribute and System.String
Whereas as far as I understand my rule, I should get this:
Foo.Bar.Apis.Controllers.FooBarController must not depend on Foo.Bar.Services.Interface.Database.IContextFactory and Foo.Bar.Services.Interface.Database.IContext`1
I've had to censor the actual namespace names, so there might be some inconsistencies but I hope you get the gist.
In order to give users a useful error, I'm currently resorting to this:
This may actually depend on how you are loading your architecture. Types() only refers to types that are directly loaded as part of an assembly included through LoadAssemblies. There are also stub types, which are only partially loaded in order to correctly include them as references of other types and are stored in Architecture.ReferencedTypes.
What I assume happens here is that you load your architecture with only your own assemblies and thus, types from System are included in Types(true) (which includes referenced types) but not Types(). So …OnlyDependOn(Types(true).That()…) should work as expected. Theres also OnlyDependsOnTypesThat which internally calls Types(true), so you could also write:
Ah thank you, that did the trick. You're correct that the architecture I'm loading consists of just our assemblies and the frameworks like Newtonsoft.Json that we use.
I really appreciate the help, I am very glad to be able to get rid of that horrible regex hack :)
Activity
drewburlingame commentedon Mar 19, 2024
I've found this annoying as well. The actual errors appear at the end of the message but it's easy to miss this with all the noise.
alexanderlinne commentedon Aug 23, 2024
Hello @wolframhaussig,
thank you for reporting this issue.
I've now been investigating this and found the following:
Types().That().ResideInNamespace("^System.*", true). On the one hand, these types are distributed among multiple namespaces and assemblies. On the other hand,ResideInAssemblycurrently matches the fully qualified name of the assembly, which not only includes it's name. We plan to change this in the future, I've createdResideInAssemblyshould not match the fully qualified name #290 to track this separately.I will link this issue as soon as the patch is ready.
richardthombsensek commentedon Dec 9, 2025
Hi @alexanderlinne are you still intending to release a patch which stops System.* types from being reported in the errors? I've just started using ArchUnitNet and I find this to be pretty annoying as I wade through the errors trying to understand what's wrong with either my code being tested or the tests I've written :)
richardthombsensek commentedon Dec 9, 2025
In fact can I go a bit further and enquire why System types are not fully excluded from the framework? Eg, filter them out when gathering types from an assembly & from type dependencies etc.
alexanderlinne commentedon Dec 9, 2025
Hi @richardthombsensek
System types are not excluded simply because there are use-cases where users want to assert that their types or methods do not depend on specific types from the
Systemnamespace.I still would like to improve this, if possible. I'm still working on improving the test coverage of and refactoring the fluent syntax, such that we can change how types are loaded and clearly see how this would affect the existing fluent syntax methods.
What will probably not happen is that
Systemtypes won't appear in the error message at all. This affects e.g.OnlyDependOnbecause you'd often have to includeSystem.*there. What I've already experimented with is excluding self-references andSystem.Objectfrom the dependencies, both may be feasible but could also have unintended side effects.Is there a specific example and error that does not make sense to you?
richardthombsensek commentedon Dec 9, 2025
Thanks for the quick reply <3
With this rule:
(I should say that ResideInAssemblyNamed is an extension method which uses ResideInAssemblyMatching and ResideInOrBelowNamespace uses ResideInNamespaceMatching with a regex to match System and System.*)
I'll get a description like this:
Whereas as far as I understand my rule, I should get this:
I've had to censor the actual namespace names, so there might be some inconsistencies but I hope you get the gist.
In order to give users a useful error, I'm currently resorting to this:
alexanderlinne commentedon Dec 9, 2025
This may actually depend on how you are loading your architecture.
Types()only refers to types that are directly loaded as part of an assembly included throughLoadAssemblies. There are also stub types, which are only partially loaded in order to correctly include them as references of other types and are stored inArchitecture.ReferencedTypes.What I assume happens here is that you load your architecture with only your own assemblies and thus, types from
Systemare included inTypes(true)(which includes referenced types) but notTypes(). So…OnlyDependOn(Types(true).That()…)should work as expected. Theres alsoOnlyDependsOnTypesThatwhich internally callsTypes(true), so you could also write:richardthombsensek commentedon Dec 9, 2025
Ah thank you, that did the trick. You're correct that the architecture I'm loading consists of just our assemblies and the frameworks like Newtonsoft.Json that we use.
I really appreciate the help, I am very glad to be able to get rid of that horrible regex hack :)