PI doesn't work with explicit interface implementation

Topics: Policy Injection Application Block, Validation Application Block
Jul 31, 2008 at 3:55 PM
The validation handler doesn't work when I use Wrap with an explicit interface implementation.
I do need the interface to be explicitly implemented so changing the implementation is not a solution.
The following doesn't throw an exception on setting the Name property to a string that is too long:


using Microsoft.Practices.EnterpriseLibrary.PolicyInjection;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers;
namespace PIApplication
{
    public interface Interface1
    {
        string Name
        {
            get;
            [method: ValidationCallHandler]
            [param: StringLengthValidator( 0, RangeBoundaryType.Inclusive, 3, RangeBoundaryType.Inclusive )]
            set;
        }
    }

    public class MyClass1 : Interface1
    {
        // Note that the interface is explicitly implemented.
        string Interface1.Name { get; set; }
    }

    class Program
    {
        static void Main( string[] args )
        {
            Interface1 i1 = new MyClass1();
            i1 = PolicyInjection.Wrap<Interface1>( i1 );
            i1.Name = "123456789"; // This should throw an exception but it doesn't!
        }
    }
}

Note that if I change the interface implementation to implicit implementation it works, but this is not acceptable for me:
public class MyClass1 : Interface1
    {
        // Implicit version which works.
        public string Name { get; set; }
    }

Any help greatly appreciated!
Sep 5, 2008 at 10:24 PM

I'm also having the same problem. It is currently preventing me from using the PIAB in my current project :(

I think this should be classified as a bug.

Did you ever find a solution/workaround?