예제 #1
0
        internal Assembly GetOrLoad(ModuleData moduleData, bool reflectionOnly)
        {
            var cache = reflectionOnly ? _reflectionOnlyAssemblyCache : _assemblyCache;

            lock (s_guard)
            {
                Assembly assembly;
                if (cache.TryGetValue(moduleData.Mvid, out assembly))
                {
                    return(assembly);
                }

                var loadedAssembly = RuntimeAssemblyManager.LoadAsAssembly(moduleData.SimpleName, moduleData.Image, reflectionOnly);

                // Validate the loaded assembly matches the value that we now have in the cache.
                if (!cache.TryGetValue(moduleData.Mvid, out assembly))
                {
                    throw new Exception("Explicit assembly load didn't update the proper cache");
                }

                if (loadedAssembly != assembly)
                {
                    throw new Exception("Cache entry doesn't match result of load");
                }

                return(assembly);
            }
        }