为什么 ResourceManager.GetResourceSet 在构建后的第一个请求上返回 null? (C#)
我正在开发一个用 C# (asp.net) 构建的大型 Web 应用程序。我有一个简单的 aspx 页面,它向客户端浏览器提供本地化字符串,以便在 javascript 控件中使用。为了获取字符串,我执行以下操作:
ResourceManager _resources = new ResourceManager(_pathname, typeof(ARM).Assembly);
ResourceSet rs = _resources.GetResourceSet(culture, false, false);
//loop through rs and write the keys & values out to the client in plaintext
这一切都工作正常,除了在清理/构建或重建之后立即向页面发出第一个请求(如果我只是进行一些更改,然后构建,它工作正常)。因此,在第一个请求中,当我尝试迭代 ResourceSet 时,我收到了空引用异常。但是,如果我在错误发生后刷新页面,那么从那时起它就可以正常工作了。
有谁知道为什么会发生这种情况?
I'm working on a large-ish web application built in C# (asp.net). I've got a simple aspx page that serves localized strings to the client browser for use in javascript controls. To get the strings, I do the following:
ResourceManager _resources = new ResourceManager(_pathname, typeof(ARM).Assembly);
ResourceSet rs = _resources.GetResourceSet(culture, false, false);
//loop through rs and write the keys & values out to the client in plaintext
This all works fine, except for the first request to the page immediately after a Clean/Build or a Rebuild (if I simply make some changes, then Build, it works fine). So on the first request I get a null reference exception when I try to iterate the ResourceSet. If I refresh the page after the error, however, it works fine from then on.
Does anyone know why this might be happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
GetResourceSet 方法的第二个参数“createIfNotExist”必须为 true,它告诉 ResourceManager 在尚未加载的情况下加载 ResourceSet。
Second param "createIfNotExist" of the method GetResourceSet has to be true, that tells ResourceManager to load the ResourceSet if not yet loaded.