internal static String GetResourceString(String key, params Object[] values)
{
if (SystemResMgr == null)
{
InitResourceManager();
}
String s;
// We unfortunately have a somewhat common potential for infinite
// loops with mscorlib's ResourceManager. If "potentially dangerous"
// code throws an exception, we will get into an infinite loop
// inside the ResourceManager and this "potentially dangerous" code.
// Potentially dangerous code includes the IO package, CultureInfo,
// parts of the loader, some parts of Reflection, Security (including
// custom user-written permissions that may parse an XML file at
// class load time), assembly load event handlers, etc. Essentially,
// this is not a bounded set of code, and we need to fix the problem.
// Fortunately, this is limited to mscorlib's error lookups and is NOT
// a general problem for all user code using the ResourceManager.
// The solution is to make sure only one thread at a time can call
// GetResourceString. If the same thread comes into GetResourceString
// twice before returning, we're going into an infinite loop and we
// should return a bogus string. -- BrianGru, 6/26/2001
// @TODO: This is a quick & easy solution, but may not be optimal.
// Note: typeof(Environment) is used elsewhere - don't lock on it.
lock (m_resMgrLockObject) {
if (m_loadingResource)
{
return("[Resource lookup failed - infinite recursion detected. Resource name: " + key + ']');
}
m_loadingResource = true;
s = SystemResMgr.GetString(key, null);
m_loadingResource = false;
}
BCLDebug.Assert(s != null, "Managed resource string lookup failed. Was your resource name misspelled? Did you rebuild mscorlib after adding a resource to resources.txt? Debug this w/ cordbg and bug whoever owns the code that called Environment.GetResourceString. Resource name was: \"" + key + "\"");
return(String.Format(s, values));
}