问题描述
我正在建在C#(asp.net)大十岁上下的Web应用程序。我有供应本地化字符串为在JavaScript控件使用客户端浏览器一个简单的aspx页面。要获取字符串,我做到以下几点:
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
这一切后,立即清洁工作正常,除第一次请求的页面/建造或重建(如果我只是做一些改变,然后生成,它工作正常)。因此,在第一次请求我得到一个空引用异常,当我尝试迭代的ResourceSet。如果我刷新页面的错误后,但是,它工作正常,从此。
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?
推荐答案
GetResourceSet必须是真实的方法的第二参数createIfNotExist,告诉的ResourceManager加载的ResourceSet如果尚未加载。
Second param "createIfNotExist" of the method GetResourceSet has to be true, that tells ResourceManager to load the ResourceSet if not yet loaded.
ResourceSet rs = _resources.GetResourceSet(culture, true, false);
这篇关于为什么ResourceManager.GetResourceSet在构建后的第一个请求返回null? (C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!