Why does ResourceManager.GetResourceSet return null on the first request after a build? (C#)

蹲街弑〆低调 提交于 2019-11-28 07:02:33

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/1646233/why-does-resourcemanager-getresourceset-return-null-on-the-first-request-after-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!