[Mono-dev] StringLengthAttribute: Inconsistent behavior with .net
Eddy Zavaleta
eddy at mictlanix.org
Sat Sep 17 10:05:13 EDT 2011
Hi,
I was testing my ASP.NET MVC 3 app on mono 2.10.5 and I have found that
mono's StringLengthAttribute class (System.ComponentModel.DataAnnotations)
have an inconsistency for localized error messages. In MS .NET the
formatting function (FormatErrorMessage) supports 3 indexed placeholders
(field name, maximum length, minimum length) for error message string and
mono only supports the first two.
Steps to reproduce the problem:
1. Create a class using StringLength validation.
2. Use "{2}" inside the ErrorMessage string.
3. Test the validation.
Code snippet:
public class TestModel
{
public TestModel()
{
}
[StringLength(10, MinimumLength = 3, ErrorMessage = "{0} must be between
{2} and {1} characters.")]
public string TestProperty { get; set; }
}
Actual Results:
System.FormatException: Index (zero based) must be greater than or equal to
zero and less than the size of the argument list.
Expected Results:
Correct formatted message: "TestProperty must be between 3 and 10
characters."
I have attach a patch that fix the problem.
--
Eddy Zavaleta
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20110917/565abcc6/attachment-0001.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: StringLengthAttribute.patch
Type: application/octet-stream
Size: 837 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20110917/565abcc6/attachment-0001.obj
More information about the Mono-devel-list
mailing list