Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
953 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...