With the Silverlight 3 Beta SDK and .NET RIA Services, a lot of people are starting to utilize the System.ComponentModel.DataAnnotations library to add validation metadata to their entities.  Something that has tripped up some people is the use of exceptions for validation errors, where Visual Studio breaks with a user unhandled exception.

As Keith Jones reported, Silverlight 3 uses exceptions to notify controls when validation has failed.  This means that many users will see Visual Studio break when these exceptions occur and be led to believe something has gone wrong.  But everything’s doing what it should.  If you hit F5 to let execution continue, you’ll see the validation error in the UI as you expect.  Also, if you run the application outside of the debugger, everything will work as you want.

There’s another way around it too; and this is what I find myself doing.  You can set your debugging options to not break on user-unhandled CLR exceptions.  Click on Debug| Exceptions and then uncheck User-unhandled Common Language Runtime Exceptions.Uncheck User-unhandled Common Language Runtime Exceptions

We’re working with the validation and data-binding folks to hopefully work out a better story in the future.