postsharp

How do I find the return type of a method with System.Reflection.MethodBase in C#?

Hi, how do I find out the return type of a method from the MethodBase? I'm using PostSharp and trying to override the CompileTimeValidate(MethodBase method) method to make sure the attribute is applied to a method with the correct signature. Thanks, ...

PostSharp OnMethodBoundaryAspect

I'm working on an aspect with postsharp 1.5 and OnMethodBoundaryAspect. I want my aspect have the following behavior by default: 1-If the attribute is used at class level the aspect is applied only on PUBLIC methods. 2-The user of the aspect can put the aspect in a private or protected method. If I use this [MulticastAttributeUsage( ...

PostSharp 1.5 InstanceTag and GetInstanceTagRequest

I'm writing an OnMethodBoundary aspect with PostSharp 1.5, and I need to store some information at instance level. So, I'm using InstanceTag that works almost fine for this. But it fail in the following scenario; if I use multicast inheritance in mode Multicast... and the aspect is applied on a new method of the derived class... The fie...

Postsharp duplicate attribute?

Can anyone explain why I'm getting this compile error? Duplicate 'Rad.Core.Aop.MethodArgumentValidation' attribute E:\Scripting\Rad.Core\Properties\AssemblyInfo.cs This is the code: [assembly: Rad.Core.Aop.MethodArgumentValidation(AttributeTargetTypes="Rad.*", AttributePriority=1)] [assembly: Rad.Core.Aop.MethodArgumentValidation(Att...

How to intercept, parse and compile?

This is a problem I've been struggling to solve for a while. I need a way to either replace code in the method with a parsed code from the template at compile time (PostSharp comes to mind) or to create a dynamic proxy (Linfu or Castle). So given a source code like this [Template] private string GetSomething() { var template = [%=Cus...

Is this fix to "PostSharp complains about CA1800:DoNotCastUnnecessarily" the best one?

This question is about "is" and "as" in casting and about CA1800 PostSharp rule. I want to know if the solution I thought is the best one possible or if it have any problem that I can't see. I have this code (named OriginaL Code and reduced to the minimum relevant). The function ValidateSubscriptionLicenceProducts try to validate a Sub...

Filtering log4net on method name - can't quite get it

I'm using log4net to log my web app's progress, using Log4PostSharp to AOP-injectify all methods. This has the desired effect of logging (almost) everything and is fine. I now have a requirement to log JUST Page_Load methods to a file / console. I can obviously hamstring the log4postsharp class to do that, but then I'd be losing all the...

How do you reflect on an attribute applied to a return value?

Consider the following: [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.ReturnValue)] public class NotNullAttribute : Attribute { } public class Class1 { [return: NotNull] public static string TestMethod([NotNull] string arg) { return arg + " + " + arg; } } How, using System.Reflection, would you...

PostSharp when using DataContractSerializer?

I have an Aspect that implements INotifyPropertyChanged on a class. The aspect includes the following: [OnLocationSetValueAdvice, MethodPointcut("SelectProperties")] public void OnPropertySet(LocationInterceptionArgs args) { var currentValue = args.GetCurrentValue(); bool alreadyEqual = (currentValue == args...

Remove PostSharp reference after build?

Is is possible to get postsharp to remove references to the postsharp assemblies during a build? I have an exe i needs to have a very small footprint. I want to use some of the compile time weaving of postsharp but dont want to have to deploy PostSharp.dll with the exe. I am using PostSharp 2 (2.0.4.1074 specifically) ...

Postsharp installer bug: .Net 2.0 not presented

There is an issue with PostSharp 1.5 and 2.0 that won't let you install it on the Windows 7 machine with the error message ".NET Framework 2.0 is not present on this computer". ...

PostSharp Cache Sample NOT working outside of the sample solution

PostSharp's Cache sample project works, but when I copy all classes and try to replicate it on my own solution, Cache does NOT happen. But build does not fail, so there must be something going on. Any tips? ...

asp.net mvc log4postsharp

Hi Iam trying to use log4post sharp for logging purposes, As far as Iam aware I have followed the instructions to get this up and running, I have not installed postsharp, rather I got the library files and midified my cs proj file to target those file, I have also tried installing postsharp on my machine. In either case I end up with th...

AssemblyLoadException in postsharp, problem with arguments from referenced DLLs?

I'm just starting out with postsharp/AOP. I want to make some instrumentation for C# to track the usage of some addins that I write for a peice of software. I am trying to use the OnMethodBoundaryAspect class to take note of the values of some of the parameters when the method is called. Those parameters are types which are referenced i...

Team City build fails after upgrade to VS 2010

Hi All, I have a project that currently compiles happily on my dev machine using VS 2010 (presumably using MSBUILD v4.0), but it fails under MSBUILD v3.5 in Team City (running on a VM based on Win 2003 server w/ .NET 2, 3.5 and 4 installed). This project is newly upgraded to 2010, and is now failing on the CI build. I've Googled this an...

Postsharp Unhandled exception simply by adding a reference

I started playing with Postsharp but cannot get past the first step. Someone else reported on their forums at http://www.sharpcrafters.com/forum/Topic4817-18-1.aspx but was wondering if anyone has come across this and perhaps have a solution. Am using VS2008 and have .net3.5SP1 installed. (Posting here as there is more activity than th...

PostSharp build targets not running when using Debug configuration

I have setup a Visual Studio project that I have edited to reference the PostSharp build targets. I did not use the MSI installed to install PostSharp on my development machine. The problem that I am having is that the PostSharp Targets are only executed when I change the build configuration to 'Release', but not in 'Debug'. I can veri...

PostSharp causes BadImageException when applied to generic methods -- errors when running peverify.exe

I just upgraded a project from VS2008/.NET 3.5/PostSharp 1.5 to VS2010/.NET4.0/PostSharp 2.0. Now, when running the unit tests for the system I get hundereds exceptions in the form of: System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) at COMPANY.Data....

PostSharp on assemblies I don't have source for

In the examples on their website, PostSharp has a demo of intercepting calls in main system assemblies. I have tried a few times to setup and replicate said intercept calls on assemblies I don't have the source code for with no success. My approach was to simply place the assembly level attribute targeting the namespace and method I wa...

Instrumentation of method calls in a web app using PostSharp

Example: I add a PostSharp attribute to a method to ensure a stopwatch is started before the method is called, and stopped just after the call returns. This method is used in a web app, so it will be called by multiple threads. I store the result of the stopwatch timing in a static threadsafe collection, for use by all threads. This c...