public static void UnloadToolboxItems() { if (_domain != null) { AppDomain domain = _domain; _domainObjectSponsor.Close(); _domainObjectSponsor = null; _domainObject = null; _domain = null; AppDomain.Unload(domain); } }
public static ICollection GetToolboxItems(AssemblyName an, bool throwOnError) { if (_domainObject == null) { _domain = AppDomain.CreateDomain("Assembly Enumeration Domain"); _domainObject = (DomainProxyObject)_domain.CreateInstanceAndUnwrap(typeof(DomainProxyObject).Assembly.FullName, typeof(DomainProxyObject).FullName); _domainObjectSponsor = new ClientSponsor(new TimeSpan(0, 5, 0)); _domainObjectSponsor.Register(_domainObject); } byte[] toolboxItems = _domainObject.GetToolboxItems(an, throwOnError); BinaryFormatter formatter = new BinaryFormatter(); return((ICollection)formatter.Deserialize(new MemoryStream(toolboxItems))); }