Skip to main content

Microsoft Silverlight

Answered Question RIA CustomValidation(...) - [Required] [StringLength(3, MinimumLength=2)] -> ValidationException was unhandled by User CodeRSS Feed

(0)

callmeknud
callmeknud

Member

Member

14 points

75 Posts

RIA CustomValidation(...) - [Required] [StringLength(3, MinimumLength=2)] -> ValidationException was unhandled by User Code

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
lee_sl

Contributor

Contributor

2992 points

585 Posts

Re: RIA CustomValidation(...) - [Required] [StringLength(3, MinimumLength=2)] -> ValidationException was unhandled by User Code

In the debug menu in VS uncheck clr exceptions and run it

----------------------------------------------
Available for consulting in Dallas, TX
http://leeontech.wordpress.com/

roncain
roncain

Member

Member

434 points

88 Posts

Answered Question

Re: RIA CustomValidation(...) - [Required] [StringLength(3, MinimumLength=2)] -> ValidationException was unhandled by User Code

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.

 

callmeknud
callmeknud

Member

Member

14 points

75 Posts

Re: Re: RIA CustomValidation(...) - [Required] [StringLength(3, MinimumLength=2)] -> ValidationException was unhandled by User Code

Thank you!

BenHayat
BenHayat

Participant

Participant

1033 points

601 Posts

Re: Re: RIA CustomValidation(...) - [Required] [StringLength(3, MinimumLength=2)] -> ValidationException was unhandled by User Code

callmeknud:

Thank you!

 

Hi, if your question was answered, please mark it as "Answered", so others can take advantage of resolved questions.

Thanks!

___________
Best Regards;
..Ben

Silverlight & WPF Insider
Please visit www.MicroIntelligence.Com For our services!

sethian
sethian

Member

Member

35 points

38 Posts

Re: Re: RIA CustomValidation(...) - [Required] [StringLength(3, MinimumLength=2)] -> ValidationException was unhandled by User Code

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.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities