postsharp in assembly
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 lin开发者_如何学编程e 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.
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?
精彩评论