I was trying to implement custom validation attribute by inheriting from ValidationAttribute and found strange thing.
My custom attribute requires validation context, so I’ve looked at the R# decompiled source of ValidationAttribute and saw, that I need override this in my custom attribute class:
public virtual bool RequiresValidationContext
{
get
{
return false;
}
}
Now the fun part – Visual Studio 2012 does not let me do that, telling me that there’s no such property for override, although when running project, in debug view I can see that property.
Interesting thing is, that in reference path I see:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.ComponentModel.DataAnnotations.dll
But in R# decompiled file is different path:
Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.ComponentModel.DataAnnotations.dll
So, compiler uses different dll from runtime.
So, I’ve tried to switch reference dll to the one R# decompiles, but looks like VS2012 is replacing it with it’s version anyway, in project file it looks like:
<Reference Include="System.ComponentModel.DataAnnotations" />
So, no path is saved in project.
Is there any solution to this without manual editing of a project?
Btw, with 4.5 NET it works fine, I mean it sees RequiresValidationContext property as supposed.
Update: As they say, picture is worth thousand words:

The solution is simple the property RequiresValidationContext was added to ValidationAttribute in .NET 4.5. Since you are coding/using/developing with C# 4.0, i suspect that you target .NET Framework 4.0 and in that version the property does not exist.
So you can´t override the property, cause it does not exist.