Skip to content

System.ComponentModel.DataAnnotations works only in PCL #4

@mfe-

Description

@mfe-

reproducible:
Use DataAnnotation for example in a WPF Project.

The Method ValidateProperties will always return true, because the linq query result is empty.

   var propertiesToValidate = _entityToValidate.GetType()
                                                        .GetRuntimeProperties()
                                                        .Where(c => c.GetCustomAttributes(typeof(ValidationAttribute)).Any());

Because the type of the DataAnnotation from the wpf project differs from the type typeof(ValidationAttribute) of the PCL project which are not equal:

wpf type
_entityToValidate.GetType().GetRuntimeProperties().ElementAt(1).GetCustomAttributes().FirstOrDefault().GetType().AssemblyQualifiedName = "System.ComponentModel.DataAnnotations.RequiredAttribute, System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
pcl type
typeof(ValidationAttribute).AssemblyQualifiedName = System.ComponentModel.DataAnnotations.ValidationAttribute, Portable.DataAnnotations, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6f21be3d5ccff8cd

Possible solution: Type comparison using Strings (e.g. Type.Name)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions