views:

469

answers:

1

I'm working on a Silverlight project with the WCF RIA Services beta. I'm using the BlahDomainService.metadata.cs file to validate a field by adding validation attributes, e.g. [RegularExpression]. It was working so I'm trying to put the Error message in a resource file and now it isn't working. The RegEx validation isn't being run on the client, though it is being run on the server.

Any idea what might be causing this?

In the generated code file on the client, I see this error:

// Unable to generate the following attribute due to the following error(s): // // - The validation attribute 'System.ComponentModel.DataAnnotations.RegularExpressionAttribute' declared ErrorMessageResourceName='RegExError' which was not found on declared ErrorMessageResourceType 'Blah.Web.Resources.SharedResources'. // [RegularExpressionAttribute("yawn", ErrorMessageResourceName = "RegExError", ErrorMessageResourceType = typeof(Blah.Web.Resources.SharedResources))]

How I got where I am

I created the SharedResources.resx (and Vs created SharedResources.Designer.cs) file in the .Web project in a folder called Resources. In the Silverlight project, I created a Web folder and in that a Resources folder. To this Resources folder, I did Add > Existing Item and then added the SharedResources.resx and .Designer.cs using the Add as Link option. The idea was that this would keep the namespaces the same for the two resources classes. I then edited the .csproj file to make the .Designer.cs file a dependency of the .resx file, using the Silverlight Business Application template as a reference.

I built the solution and tested it and the RegEx validation throws no error, which is bad. Then I found the message above. To verify that my linking was working, in Home.xaml.cs, I typed:

System.Diagnostics.Debug.WriteLine(Web.Resources.SharedResources.RegExError);

and saw the error in the Output window in VS. I also submitted the changes to the service and in the EntitiesInError, on the VaidationErrors, I can see the error message, so I know it's working server-side. It's just the client-side that isn't. Any idea why it's not working?

A: 

Everything was okay except that I hadn't set the AccessModifier for the .resx to Public. Once I'd done that and Rebuilt All, it worked.

serialhobbyist
i am also facing same problem can you explain solution in detail plz.thanks
Kuldip Saini
Right-click on the .resx file name in Visual Studio. Select Open. Across the top you'll see Strings - Add Resource - Remove Resource - [Tools icon] - Access Modifier - select Public in the drop-down.
serialhobbyist