Is there any way I can implement IValidatableObject on Portable Class Library Project?

There’s probably not an easy solution for this. You can create your own interface in a Portable Class Library with the same functionality. However that would be a different interface so other frameworks that use DataAnnotations (ASP.NET MVC and Entity Framework I think) wouldn’t use your version.

To get around that problem, you could create a PCL with the interface with the exact same name and APIs as exist on the different platforms. Then create class libraries for .NET 4.0.3, SL4, and Windows Store with the exact same assembly identity (name, version, and strong name key), and in those assemblies just put a [assembly:TypeForwardedToAttribute(typeof(IValidatableObject))] attribute.

Then your PCLs can reference the PCL library with the interface, and in any apps that use the PCLs, reference the type-forwarding assembly for that platform, which will redirect the reference to the PCL version of the interface to the one that comes in the platform.

Leave a Comment