装配中的后锐化
我有一个 postsharp 属性,用于处理整个 dll 中的异常(该 ddl 由其他团队提供)并管理数据库调用。 因此,我们的想法是使用 postsharp 处理异常。
因此,这是一个属性
[Serializable]
public class MethodConnectionTracking: OnExceptionAspect
{
bool canceled = false;
public override void OnException(MethodExecutionArgs args)
{
Exception ex = args.Exception;
if (ex != null)
{
--- do things
}
}
}
,可以使该属性起作用并拦截我拥有的名为 SPData 的项目的 assemblyInfo.cs 中的所有方法:
[assembly: MethodConnectionTracking(AttributeTargetElements = MulticastTargets.Method)]
并且效果很好。但我想在其他项目中指定该行。
因此,主项目引用了 SPData。因此,在主项目 AssemblyInfo.cs 文件中我写道:
[assembly: MethodConnectionTracking(AttributeTargetAssemblies = "SPData", AttributeTargetElements = MulticastTargets.Method)]
但它不起作用。
是否可以做我想做的事情,我是否缺少一些参数?
提前致谢。
I have an postsharp attribute for handling exceptions in a entire dll ( that ddl is provided by other team) and manage database calls.
So the idea is treat the exceptions with postsharp
So, this is the attribute
[Serializable]
public class MethodConnectionTracking: OnExceptionAspect
{
bool canceled = false;
public override void OnException(MethodExecutionArgs args)
{
Exception ex = args.Exception;
if (ex != null)
{
--- do things
}
}
}
to make that works and intercept all methods in the assemblyInfo.cs for that project called SPData i have:
[assembly: MethodConnectionTracking(AttributeTargetElements = MulticastTargets.Method)]
and that works great. But i want to specify that line in other project.
So, the main project references SPData. So, in main project AssemblyInfo.cs file i write:
[assembly: MethodConnectionTracking(AttributeTargetAssemblies = "SPData", AttributeTargetElements = MulticastTargets.Method)]
But it does not work.
Is it possibly to do what i want, Am I missing some parameter?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要 AttributeTargetElements = MulticastTargets.Method,因为使用 OnExceptionAspect 基类时已经提供了
您不需要检查 ex != null 是否为 null,因为它永远不会为 null,因为除非出现异常,否则不会调用 OnException。请参阅http://programmersunlimited.wordpress.com /2011/08/01/postsharp-why-are-my-arguments-null/
您确定您拥有正确的程序集名称吗?您使用命名空间吗?您需要使用实际的程序集名称(不带 .dll)。尝试使用通配符“SPData*”,看看是否有帮助。
您是否使用 ILSpy 单步调试了代码或查看了编译后的程序集?除非您提供了错误的名称,否则它应该可以工作。是对项目还是编译后的程序集的引用?程序集是否经过签名或混淆?
You don't need AttributeTargetElements = MulticastTargets.Method as it is already provided when using OnExceptionAspect base class
You don't need to check if ex != null because it will never be null as OnException won't be invoked unless there is an exception. See http://programmersunlimited.wordpress.com/2011/08/01/postsharp-why-are-my-arguments-null/
Are you sure you have the correct assembly name? Are you using the namespace? You need to use the actual assembly name (without the .dll). Try a wildcard "SPData*" and see if that helps.
Have you stepped through the code or looked at the compiled assembly using ILSpy? Unless you are providing the wrong name, it should work. Is the reference to a project or a compiled assembly? Is the assembly signed or obfuscated?