It was because I had forgotten to change the filename to have the .Shared.cs extension. Then I needed to do a clean and build again.
Thanks all for the help. T. On Thu, Jan 28th, 2010 at 5:06 PM, Chris Anderson <christheco...@gmail.com> wrote: > Try deleting the contents of the Generated_Code folder (it's hidden, > use > Show All Files to see it) - sometimes RIA Services stops updating the > code > files, but deleting them will get it generating them properly again. > Also > make sure that your custom validation code is in a .shared.cs file so > it is > being copied to the client. > > Chris Anderson > > > 2010/1/28 <ton...@tpg.com.au> > > > It's ok, I think I figured it out. The attribute is not available > on the > > client side. Within the generated > > code for the class, it was missing the TermCustomValidation class > and it > > has the following > > message. So now I just have to figure out why the class isn't > coming across > > to the client. > > > > T. > > > > // Unable to generate the following attribute due to the following > > error(s): > > // > > // - The attribute > > 'System.ComponentModel.DataAnnotations.CustomValidationAttribute' > > references type 'Brightstar.SSP.Web.Shared.TermCustomValidation' > that is > > not accessible in the > > client project 'Brightstar.SSP.csproj'. Are you missing an > assembly > > reference? > > // - The attribute > > 'System.ComponentModel.DataAnnotations.CustomValidationAttribute' > > references a method 'EnsureTermCategory' on > > type 'Brightstar.SSP.Web.Shared.TermCustomValidation' that is not > > accessible in the client > > project 'Brightstar.SSP.csproj'. > > // [CustomValidationAttribute(typeof > > (Brightstar.SSP.Web.Shared.TermCustomValidation), > "EnsureTermCategory", > > ErrorMessageResourceName = "TTermCategoryRequiredError", > > ErrorMessageResourceType = > > typeof(Brightstar.SSP.Web.Resources.ValidationErrorResources))] > > // > > > > > > > > > > On Thu, Jan 28th, 2010 at 4:33 PM, ton...@tpg.com.au wrote: > > > > > I just reflected over the code and found that it was using some > > > reflection to retrieve the custom > > > attributes. So I added in this code to see if the attributes > were, in > > > fact, visible. > > > > > > foreach (PropertyInfo info in > > > typeof(Term).GetProperties()) > > > { > > > foreach (Attribute attribute in > > > info.GetCustomAttributes(true).Cast<Attribute>()) > > > { > > > Debug.WriteLine(attribute); > > > } > > > } > > > > > > And the answer is that it can see all the normal attributes, such > as > > > RequiredAttribute, > > > DisplayAttribute, etc, but NOT the CustomValidationAttribute. > Note > > > that I have done a clean before > > > building. I don't know why it's not recognising the > CustomValidation > > > attribute. Perhaps it is > > > something to do with the meta data needing to map the particular > > > attribute to the original class? > > > > > > T. > > > > > > On Thu, Jan 28th, 2010 at 3:32 PM, ton...@tpg.com.au wrote: > > > > > > > Hi Miguel, > > > > > > > > I ran the code: > > > > var ctx = new ValidationContext(dfTermItem.CurrentItem, null, > null) > > > { > > > > MemberName > > > > = "TermCategoryID" }; > > > > var validationResults = new Collection<ValidationResult>(); > > > > //validate against a guid that should fail > > > > if (Validator.TryValidateProperty(new > > > > Guid("00000000-0000-0000-0022-000000000002"), ctx, > > > > validationResults)) > > > > { > > > > Debug.WriteLine("Success"); > > > > } > > > > else > > > > { > > > > Debug.WriteLine("Fail"); > > > > } > > > > > > > > It always returns "Success" and unfortunately, it didn't fire > the > > > > Custom Validator at all. > > > > > > > > dfTermItem.CurrentItem is of type "Term" > > > > > > > > Term has a property TermCategoryID > > > > > > > > In the metadata.cs file, TermCategoryID is declared as > follows: > > > > > > > > [CustomValidation(typeof > > > > > > > > (TermCustomValidation),"EnsureTermCategory",ErrorMessageResourceName > > > > > > > > = "TTermCategoryRequiredError", ErrorMessageResourceType = > typeof > > > > (ValidationErrorResources))] > > > > [Bindable(true, BindingDirection.TwoWay)] > > > > public Guid TermCategoryID; > > > > > > > > TermCustomValidation is a static class: > > > > public static class TermCustomValidation > > > > { > > > > > > > > public static ValidationResult EnsureTermCategory(Guid > > > > TermCategoryID, ValidationContext > > > > validationContext) > > > > { > > > > Term currentTerm = validationContext.ObjectInstance > as > > > > Term; > > > > if (currentTerm != null) > > > > { > > > > if (currentTerm.TermCategoryID == Guid.Empty) > > > > { > > > > return new ValidationResult("Term Type is > a > > > > required field."); > > > > } > > > > > > > > //fyi, EnumHelper.GetID simply returns a guid from an > attribute > > > > attached to an enum value > > > > if > > > > > > > > (currentTerm.TermCategoryID==EnumHelper.GetID(TermCategoryList.Vendor)) > > > > { > > > > if (currentTerm.VendorID == null || > > > > currentTerm.VendorID == Guid.Empty) > > > > { > > > > return new ValidationResult("Vendor is > > > > required when a Vendor Term Type is > > > > selected."); > > > > } > > > > } > > > > else if (currentTerm.TermCategoryID == > > > > EnumHelper.GetID(TermCategoryList.Model)) > > > > { > > > > if (currentTerm.ModelID == null || > > > > currentTerm.ModelID == Guid.Empty) > > > > { > > > > return new ValidationResult("Vendor, > Brand > > > > and Model are required when a Model > > > > Term Type is selected."); > > > > } > > > > } > > > > } > > > > return ValidationResult.Success; > > > > } > > > > > > > > > > > > Note that it never actually debugs into the EnsureTermCategory > > > > method. > > > > > > > > I would have thought it would have returned "Failed"! > > > > > > > > Regards, > > > > Tony > > > > > > > > > > > > From: ozsilverlight-boun...@ozsilverlight.com > > > > [mailto:ozsilverlight-boun...@ozsilverlight.com] On > > > > Behalf Of Miguel Madero > > > > Sent: Thursday, 28 January 2010 11:10 AM > > > > To: ozSilverlight > > > > Subject: Re: RIA Domain Services and required dependencies > > > > > > > > > > > > > > > > I've not experienced that issue. Try to explicitly validate > the > > > > property to see if that's an issue with > > > > the DataForm or just with how you set up the validation. > > > > > > > > > > > > > > > > var ctx = new ValidationContext(this, null, null) { MemberName > > > > = "NameOfYourPropertyGoesHere" }; > > > > > > > > var validationResults = new Collection<ValidationResult>(); > > > > > > > > if (Validator.TryValidateProperty("yourNewValueGoesHere", ctx, > > > > validationResults)) > > > > > > > > // It was valid > > > > > > > > else > > > > > > > > // it wasn't valid, check the validationResults for details > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Could you also try it with the example on the link I sent? > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > Miguel A. Madero Reyes > > > > www.miguelmadero.com (blog) > > > > m...@miguelmadero.com > > > > > > > > _______________________________________________ > > > > ozsilverlight mailing list > > > > ozsilverlight@ozsilverlight.com > > > > http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight > > > > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > ozsilverlight mailing list > > > ozsilverlight@ozsilverlight.com > > > http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight > > > > > > > > > > > > > > > > > _______________________________________________ > > ozsilverlight mailing list > > ozsilverlight@ozsilverlight.com > > http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight > > > _______________________________________________ ozsilverlight mailing list ozsilverlight@ozsilverlight.com http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight