private static AssemblyName GetAssemblyName(Assembly assembly)
        {
            object key = assembly.IsDynamic ? ((object)new WeakRefKey(assembly)) : ((object)assembly);

            lock (syncObject)
            {
                AssemblyName name;
                if (_assemblies == null)
                {
                    _assemblies = new Dictionary <object, AssemblyName>();
                }
                else if (_assemblies.TryGetValue(key, out name))
                {
                    return(name);
                }
                name = new AssemblyName(assembly.FullName);
                _assemblies.Add(key, name);
                if (assembly.IsDynamic && !_isGCCallbackPending)
                {
                    GCNotificationToken.RegisterCallback(new WaitCallback(SafeSecurityHelper.CleanupCollectedAssemblies), null);
                    _isGCCallbackPending = true;
                }
                return(name);
            }
        }
Exemple #2
0
 private void RegisterAssemblyCleanup()
 {
     lock (this._syncAccessingUnexaminedAssemblies)
     {
         if (!this._isGCCallbackPending)
         {
             GCNotificationToken.RegisterCallback(new WaitCallback(XamlSchemaContext.CleanupCollectedAssemblies), new WeakReference(this));
             this._isGCCallbackPending = true;
         }
     }
 }
        private static void CleanupCollectedAssemblies(object state)
        {
            bool          flag = false;
            List <object> list = null;

            lock (syncObject)
            {
                foreach (object obj2 in _assemblies.Keys)
                {
                    WeakReference reference = obj2 as WeakReference;
                    if (reference != null)
                    {
                        if (reference.IsAlive)
                        {
                            flag = true;
                        }
                        else
                        {
                            if (list == null)
                            {
                                list = new List <object>();
                            }
                            list.Add(obj2);
                        }
                    }
                }
                if (list != null)
                {
                    foreach (object obj3 in list)
                    {
                        _assemblies.Remove(obj3);
                    }
                }
                if (flag)
                {
                    GCNotificationToken.RegisterCallback(new WaitCallback(SafeSecurityHelper.CleanupCollectedAssemblies), null);
                }
                else
                {
                    _isGCCallbackPending = false;
                }
            }
        }