为什么我的共享资源文件在我的 Silverlight RIA 项目中不起作用? [英] Why isn't my shared resource file working in my Silverlight RIA project?

查看:54
本文介绍了为什么我的共享资源文件在我的 Silverlight RIA 项目中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 WCF RIA 服务测试版进行 Silverlight 项目.我正在使用 BlahDomainService.metadata.cs 文件通过添加验证属性来验证字段,例如[正则表达式].它正在工作,所以我试图将错误消息放入资源文件中,但现在无法正常工作.尽管 RegEx 验证在服务器上运行,但并未在客户端上运行.

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:

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

我是如何走到今天的

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

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.

我构建了解决方案并对其进行了测试,RegEx 验证没有抛出任何错误,这很糟糕.然后我找到了上面的消息.为了验证我的链接是否有效,我在 Home.xaml.cs 中输入:

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);

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

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?

推荐答案

一切正常,只是我没有将 .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.

这篇关于为什么我的共享资源文件在我的 Silverlight RIA 项目中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆