为什么我的共享资源文件无法在我的 Silverlight RIA 项目中工作?

发布于 2024-09-27 03:36:00 字数 1339 浏览 1 评论 0原文

我正在使用 WCF RIA Services beta 开发一个 Silverlight 项目。我使用 BlahDomainService.metadata.cs 文件通过添加验证属性(例如 [RegularExpression])来验证字段。它正在工作,所以我试图将错误消息放入资源文件中,但现在它不起作用。尽管正则表达式验证正在服务器上运行,但它并未在客户端上运行。

知道是什么原因造成的吗?

在客户端生成的代码文件中,我看到以下错误:

// 由于以下错误而无法生成以下属性: // // - 验证属性“System.ComponentModel.DataAnnotations.RegularExpressionAttribute”声明了 ErrorMessageResourceName=“RegExError”,但在声明的 ErrorMessageResourceType“Blah.Web.Resources.SharedResources”上找不到该属性。 // [RegularExpressionAttribute("yawn", ErrorMessageResourceName = "RegExError", ErrorMessageResourceType = typeof(Blah.Web.Resources.SharedResources))]

我如何到达现在的位置

我创建了 SharedResources .resx(以及 Vs 创建的 SharedResources.Designer.cs)文件位于 .Web 项目中名为 Resources 的文件夹中。在 Silverlight 项目中,我创建了一个 Web 文件夹,并在其中创建了一个 Resources 文件夹。对于这个资源文件夹,我做了添加>现有项,然后使用“添加为链接”选项添加 SharedResources.resx 和 .Designer.cs。我们的想法是,这将使两个资源类的命名空间保持相同。然后,我使用 Silverlight 业务应用程序模板作为参考,编辑 .csproj 文件以使 .Designer.cs 文件成为 .resx 文件的依赖项。

我构建了解决方案并对其进行了测试,正则表达式验证没有抛出任何错误,这很糟糕。然后我发现了上面的消息。为了验证我的链接是否正常工作,我在 Home.xaml.cs 中键入:

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

并在“输出”窗口中看到错误在VS中。我还提交了对服务的更改,并且在 EntitiesInError 和 VaidationErrors 中,我可以看到错误消息,所以我知道它正在服务器端工作。只是客户端不是这样。知道为什么它不起作用吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

起风了 2024-10-04 03:36:00

您还可以在 Web 项目的客户端 silverlight 项目中添加资源 (.resx) 作为链接。
请参阅 VS 2010 中的 Silverlight Business Application 模板。它有一个非常好的示例。

You also have add a resources (.resx) as a link in the client silverlight project for the web project.
See template Silverlight Bussiness Application in VS 2010. It has a very good sample.

夜声 2024-10-04 03:36:00

一切都很好,除了我没有将 .resx 的 AccessModifier 设置为 Public。当我完成此操作并重建全部后,它就起作用了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文