Asked by:
[UWP]Validator will throw an exception when call its method.

Question
-
I test the same code on console platform, it is no problem.
But when I call the method on UWP, it throw an exception to me.
Here is link for the test project: http://1drv.ms/1IOvtMc
Does anybody can contact MS to fix this?
- Edited by h82258652 Tuesday, May 19, 2015 4:10 PM
Tuesday, May 19, 2015 4:09 PM
All replies
-
Can you please provide details of the problem?
What exactly are you doing? What is the expected behavior? What is the actual behavior?
Including a zip (not .7z) file with a minimal repro is helpful but not sufficient.
Tuesday, May 19, 2015 4:47 PMModerator -
The zip link: http://1drv.ms/1FxIJpw
Here is the console code:
using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using ValidationTest.Shared; namespace ValidationTest.Console { internal class Program { private static void Main(string[] args) { Person person = new Person() { Name = "Damn_it" }; ValidationContext context = new ValidationContext(person) { MemberName = "Name" }; List<ValidationResult> results = new List<ValidationResult>(); bool isValidate = Validator.TryValidateProperty(person.Name, context, results); System.Console.WriteLine(isValidate); System.Console.ReadKey(); } } }
It will output: False.
And I copy this code to my UWP project.
using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using ValidationTest.Shared; using Windows.UI.Popups; using Windows.UI.Xaml.Controls; // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 namespace ValidationTest.Universal { /// <summary> /// An empty page that can be used on its own or navigated to within a Frame. /// </summary> public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); } private async void GoTest() { Person person = new Person() { Name = "Damn_it" }; ValidationContext context = new ValidationContext(person) { MemberName = "Name" }; List<ValidationResult> results = new List<ValidationResult>(); bool isValidate = Validator.TryValidateProperty(person.Name, context, results); await new MessageDialog(isValidate.ToString()).ShowAsync(); } } }
And run.
It throw an ArgumentNullException to me. If no problem, it should continue to run and show a message dialog which message is False.
You can see the three arguments of this method are both not null. So I think it is this API problem.
The person class definition:
using System.ComponentModel; using System.ComponentModel.DataAnnotations; namespace ValidationTest.Shared { public class Person : INotifyPropertyChanged { public string _name; public event PropertyChangedEventHandler PropertyChanged; [StringLength(5)] public string Name { get { return _name; } set { _name = value; if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(nameof(Name))); } } } } }
And sorry for my terrible English.
Tuesday, May 19, 2015 5:37 PM -
Thanks for the clarification. I can reproduce this on Windows 10. The same code in a Windows 8.1 app works fine.
I'll file a bug on this.
Wednesday, May 20, 2015 1:34 AMModerator