I have a Visual Studio 2015 solution, into which I have copied-and-pasted a number of PostSharp validation attributes that I had been successfully using on a Visual Studio 2013 project.
The project all compiles and runs successfully. Unfortunately though, unit tests designed to test my validation attributes are failing. From debugging I have found that none of my attributes are ever being run. I have ensured that the PostSharp package is referenced correctly in the project references as well as in the .xproj file.
My Validation Attribute code is like:
using System;
using PostSharp.Aspects;
using PostSharp.Reflection;
namespace Foo.Domain.Model.ValidationAttributes
{
/// <summary>
/// Validates the parameter to strictly not be null (empty and whitespace is valid). Throws a System.ArgumentNullException if assigned a null value.
/// </summary>
[Serializable]
public sealed class NotNullAttribute : LocationInterceptionAspect, ILocationValidationAspect<object>
{
public NotNullAttribute()
{
}
public override void OnSetValue(LocationInterceptionArgs args)
{
Exception ex = ValidateValue(args.Value, args.LocationName, args.Location.LocationKind);
if (ex != null)
{
throw ex;
}
args.ProceedSetValue();
}
public Exception ValidateValue(object value, string locationName, LocationKind locationKind)
{
return value == null ? new ArgumentNullException(locationName, string.Format("The parameter '{0}' may not be null.", locationName)) : null;
}
}
}
My project.json shows the added dependencies:
{
"version": "1.0.0-*",
"description": "MyProject Domain Class Library",
"tags": [ "MyProject" ],
"projectUrl": "",
"licenseUrl": "",
"dependencies": {
"PostSharp": "4.1.21",
"PostSharp.Patterns.Common": "4.1.21",
"PostSharp.Patterns.Model": "4.1.21"
},
"frameworks": {
"net451": { }
}
}
And my .xproj file shows the added PostSharp target (I've checked it exists at the path):
<Import Project="..\packages\PostSharp\4.1.21\tools\PostSharp.targets" />
From the PostSharp documentation it appears that VS2015 is fully supported, but I can't seem to get these aspects to work. Is there anything I need to do to get PostSharp up and running on Visual Studio 2015?