PostSharp Conflicting Aspects warning

2019-06-21 06:29发布

I'm using PostSharp Express in VS2013 to create validation aspects which I can apply to my properties. I followed this PostSharp guide on location interception. They all work well but I am getting hundreds of warnings stating:

Conflicting aspects on "MyNamespace.get_MyProperty": transformations ".MyValidation1Attribute: Intercepted by advice OnGetValue, OnSetValue" and "MyNamespace.Validation2Attribute: Intercepted by advice OnGetValue, OnSetValue" are not commutative, but they are not strongly ordered. Their order of execution is undeterministic.

Which I think is a result of my placing multiple validation aspects on the same properties. First I tried to comma-separate the attributes, which I understand is supposed to order them: [Validation1,Validation2] but the warnings still remained.

Since my aspects are commutative (it doesn't matter which order they are executed), the PostSharp docs advise to mark them as such using AspectTypeDependency as follows:

[AspectTypeDependency(AspectDependencyAction.Commute, typeof(ILocationValidationAspect))]

However, it appears that the PostSharp.Aspects.Dependencies namespace is not included under the Express license. Is there any possible solution to resolving these warnings using only the Express license? Or does this mean I can't ever use more than one aspect without buying pro or ultimate? I would be willing to try to implement my own dependency controller if I could remove these warnings this way.

1条回答
我只想做你的唯一
2楼-- · 2019-06-21 07:01

AspectTypeDependency requires Professional edition. But the AspectTypeDependency type should be included even in Express edition - there should be using non-licensed feature build time error then.

You can use AspectPriority:

[Validation1(AspectPriority = 1), Validation2(AspectPriority = 2)]

Alternatively you can assign the priority in aspect constructor. It is much less flexible than aspect ordering but at least it resolves the warning.

查看更多
登录 后发表回答