diff --git a/src/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/DataTypeAttribute.cs b/src/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/DataTypeAttribute.cs index 96ee5e5ee037..e398ad3f50b8 100644 --- a/src/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/DataTypeAttribute.cs +++ b/src/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/DataTypeAttribute.cs @@ -115,7 +115,7 @@ public override bool IsValid(object value) /// is thrown if the current attribute is ill-formed. private void EnsureValidDataType() { - if (DataType == DataType.Custom && string.IsNullOrEmpty(CustomDataType)) + if (DataType == DataType.Custom && string.IsNullOrWhiteSpace(CustomDataType)) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, SR.DataTypeAttribute_EmptyDataTypeString)); diff --git a/src/System.ComponentModel.Annotations/tests/DataTypeAttributeTests.cs b/src/System.ComponentModel.Annotations/tests/DataTypeAttributeTests.cs index 487137bf9d25..3aa385bebdb0 100644 --- a/src/System.ComponentModel.Annotations/tests/DataTypeAttributeTests.cs +++ b/src/System.ComponentModel.Annotations/tests/DataTypeAttributeTests.cs @@ -68,6 +68,7 @@ public static void GetDataTypeName_InvalidDataType_ThrowsIndexOutOfRangeExceptio [Theory] [InlineData("CustomValue")] [InlineData("")] + [InlineData(" ")] [InlineData(null)] public static void Ctor_String(string customDataType) { @@ -75,7 +76,7 @@ public static void Ctor_String(string customDataType) Assert.Equal(DataType.Custom, attribute.DataType); Assert.Equal(customDataType, attribute.CustomDataType); - if (string.IsNullOrEmpty(customDataType)) + if (string.IsNullOrWhiteSpace(customDataType)) { Assert.Throws(() => attribute.GetDataTypeName()); Assert.Throws(() => attribute.Validate(new object(), s_testValidationContext));