Skip to main content
Home Forums Silverlight Programming WCF RIA Services RIA CustomValidation(...) - [Required] [StringLength(3, MinimumLength=2)] -> ValidationException was unhandled by User Code
5 replies. Latest Post by sethian on July 24, 2009.
(0)
callmeknud
Member
14 points
75 Posts
04-01-2009 9:02 AM |
Hello,
i followed the RIA Overview PDF and added a shared.cs file to my Project in which i validate some other fields which works fine.but if i add something like:
[Required][StringLength(3, MinimumLength=3)]public string plz;to the metadata i get the error: ValidationException was unhandled by User Code.I thought it would just display the user that field plz hast to be at least 3 and at max 3 characters long.How and where do i have to handle the Exception in my code?thanks!
lee_sl
Contributor
2992 points
585 Posts
04-01-2009 9:44 AM |
In the debug menu in VS uncheck clr exceptions and run it
roncain
434 points
88 Posts
04-01-2009 12:20 PM |
Yes, that is the right thing to do for now.
What is happening is that the Debugger is set by default to catch uncaught user exceptions, and if you run from the debugger when validation exceptions are thrown, you break to the debugger.
We're working with the validation and data-binding folks to work out a better story to avoid this exception being unhandled.
But your life will be simpler in the meantime if you use the Debug | Exceptions menu and uncheck "User-unhandled". This does not prevent the app from seeing these exceptions. It just stops the debugger from breaking when they occur.
04-02-2009 2:29 AM |
Thank you!
BenHayat
Participant
1033 points
601 Posts
04-02-2009 9:03 AM |
callmeknud:Thank you!
Hi, if your question was answered, please mark it as "Answered", so others can take advantage of resolved questions.
Thanks!
sethian
35 points
38 Posts
07-24-2009 11:23 AM |
Going into Debug->Exceptions and simply clearing the clr check box is not the best work around for this problem.
You should add the exception:
System.ComponentModel.DataAnnotations.ValidationException
and clear the User-unhandled for only that particular one (since that's what's getting thrown).
Otherwise all user-unhandled clr exceptions will not cause a break in the debugger, and you won't know when your code is throwing an exception.