PostSharp 方面不编译和触发

PostSharp aspect don't compile and fire

我的 PostSharp 有问题,简而言之可以描述为 "some aspects don't fire and are not shown in PostSharp Explorer"。

如屏幕截图所示,从 MethodInterceptorAspect 继承的 Authorization 命名空间的两个方面在 PostSharp 资源管理器中显示,而从 OnExceptionAspect 派生的 ExceptionHandling 命名空间的两个新方面则没有。

下面是其中一个的代码:一个'standard'手工制作的aspect,除了派生自另一个baseclass外,几乎和working aspets一样。我试图通过注释代码的不同部分来确定问题,但没有帮助。

[Serializable]
[AttributeUsage(AttributeTargets.All)]
public class HandleExceptionAttribute : OnExceptionAspect
{
    /// <summary>
    /// Method executed <b>after</b> the body of methods to which this aspect is applied,
    ///               in case that the method resulted with an exception (i.e., in a <c>catch</c> block).
    /// </summary>
    /// <param name="args">Advice arguments.</param>
    public override void OnException(MethodExecutionArgs args)
    {
        // some exception handling code
    }
}

此外,我刚刚从 sample 添加了一个简单的方面,它也没有在 PostSharp Explorer 中显示。

问题

所以问题是:为什么方面不编译和触发?

正在回答我自己的问题/问题已更新

这似乎是 PostSharp 的一个错误,或者可能是 PostSharp、ReSharper 和 Visual Studio 之间的冲突。

在抽象方法上应用 一个 新方面后(以前的方面在 class 级别应用)我有一个关于 'incompatibilty' 的构建错误.然后我将抽象方法虚拟化并成功编译了项目。 Resharper Explorer 显示了两个 新方面及其所有影响。为了清楚起见,我做了 'undo changes' 并想重复我的操作,但是这次所有方面都从 PostSharp Explorer 中消失了,就像它们根本没有应用一样(虽然它们仍然应用了大约 300 次)并且 ReSharper 突出显示了所有方面作为未知类型的用法。

挂起ReSharper,清除解决方案,重启VisualStudio,重建解决方案后,PostSharp资源管理器中出现了三个方面,在项目中再次应用PostSharp后出现了第四个方面,这里用到了这个方面。

因此,如果您的方面没有触发 - 请检查您在使用 aspets 的项目中的 PostSharp 设置。

相关问答:

  • applying aspect defined in one project, to methods in other projects of solution
  • 'Add PostSharp to this project' no action

感谢@Jakub 指导评论!