System.Environment.ResourceHelper.GetResourceStringCode C# (CSharp) Method

GetResourceStringCode() private method

private GetResourceStringCode ( Object userDataIn ) : void
userDataIn Object
return void
            private void GetResourceStringCode(Object userDataIn)
            {
                GetResourceStringUserData userData = (GetResourceStringUserData) userDataIn;
                ResourceHelper rh = userData.m_resourceHelper;
                String key = userData.m_key;

                Monitor.ReliableEnter(rh, ref userData.m_lockWasTaken);

                // Are we recursively looking up the same resource?
                if (rh.currentlyLoading != null && rh.currentlyLoading.Count > 0 && rh.currentlyLoading.Contains(key)) {
                    // This is often a bug in the BCL, security, NLS+ code,
                    // or the loader somewhere.  However, this could also
                    // be a setup problem - check whether mscorlib & 
                    // mscorwks are both of the same build flavor.
                    String stackTrace = "[Couldn't get a stack trace]";
                    try 
                    {
                        StackTrace st = new StackTrace(true);
                        // Don't attempt to localize strings in this stack trace, otherwise it could cause
                        // infinite recursion. This stack trace is used for an Assert message only, and
                        // so the lack of localization should not be an issue.
                        stackTrace = st.ToString( System.Diagnostics.StackTrace.TraceFormat.NoResourceLookup );
                    }
                    catch(StackOverflowException) {}
                    catch(NullReferenceException) {}
                    catch(OutOfMemoryException) {}

                    BCLDebug.Assert(false, "Infinite recursion during resource lookup.  Resource name: "+key+"\r\n"+stackTrace);
                   
                    // Note: can't append the key name, since that may require
                    // an extra allocation... 
                    userData.m_retVal = "[Resource lookup failed - infinite recursion or critical failure detected.]";
                    return;
                }
                if (rh.currentlyLoading == null)
                    rh.currentlyLoading = new Stack(4);

                // Call class constructors preemptively, so that we cannot get into an infinite
                // loop constructing a TypeInitializationException.  If this were omitted,
                // we could get the Infinite recursion assert above by failing type initialization
                // between the Push and Pop calls below.
		
                if (!rh.resourceManagerInited)
                {
                    // process-critical code here.  No ThreadAbortExceptions
                    // can be thrown here.  Other exceptions percolate as normal.
                    RuntimeHelpers.PrepareConstrainedRegions();
                    try {
                    }
                    finally {
                        RuntimeHelpers.RunClassConstructor(typeof(ResourceManager).TypeHandle);
                        RuntimeHelpers.RunClassConstructor(typeof(ResourceReader).TypeHandle);
                        RuntimeHelpers.RunClassConstructor(typeof(RuntimeResourceSet).TypeHandle);
                        RuntimeHelpers.RunClassConstructor(typeof(BinaryReader).TypeHandle);
                        rh.resourceManagerInited = true; 
                    }
		    
                } 
		
                rh.currentlyLoading.Push(key);
                if (rh.SystemResMgr == null)
                    rh.SystemResMgr = new ResourceManager("mscorlib", typeof(Object).Assembly);
                String s = rh.SystemResMgr.GetString(key, null);
                rh.currentlyLoading.Pop();

                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 rhironment.GetResourceString.  Resource name was: \""+key+"\"");

                userData.m_retVal = s;
            }