/// <summary>
        /// Load a SerializerDescriptor from the registry 
        /// </summary> 
        /// <remarks>
        ///     Create a SerializerDescriptor from the registry 
        ///
        ///     This method currently requires full trust to run.
        /// </remarks>
        ///<SecurityNote> 
        ///  The DemandPlugInSerializerPermissions() ensures that this method only works in full trust.
        ///  Full trust is required, so that partial trust applications do not load or use potentially 
        ///  unsafe serializer plug ins 
        ///</SecurityNote>
        internal static SerializerDescriptor CreateFromRegistry(RegistryKey plugIns, string keyName) 
        {
            SecurityHelper.DemandPlugInSerializerPermissions();

            SerializerDescriptor sd = new SerializerDescriptor(); 

            try 
            { 
                RegistryKey key = plugIns.OpenSubKey(keyName);
 
                sd._displayName = GetNonEmptyRegistryString(key, "displayName");
                sd._manufacturerName =          GetNonEmptyRegistryString(key, "manufacturerName");
                sd._manufacturerWebsite =       new Uri(GetNonEmptyRegistryString(key, "manufacturerWebsite"));
                sd._defaultFileExtension =      GetNonEmptyRegistryString(key, "defaultFileExtension"); 

                sd._assemblyName =              GetNonEmptyRegistryString(key, "assemblyName"); 
                sd._assemblyPath =              GetNonEmptyRegistryString(key, "assemblyPath"); 
                sd._factoryInterfaceName =      GetNonEmptyRegistryString(key, "factoryInterfaceName");
                sd._assemblyVersion =           new Version(GetNonEmptyRegistryString(key, "assemblyVersion")); 
                sd._winFXVersion =              new Version(GetNonEmptyRegistryString(key, "winFXVersion"));

                string uiLanguage =             GetNonEmptyRegistryString(key, "uiLanguage");
 
                key.Close();
 
                // update language strings. 
                if (!uiLanguage.Equals(CultureInfo.CurrentUICulture.Name))
                { 
                    ISerializerFactory factory = sd.CreateSerializerFactory();

                    sd._displayName = factory.DisplayName;
                    sd._manufacturerName = factory.ManufacturerName; 
                    sd._manufacturerWebsite = factory.ManufacturerWebsite;
                    sd._defaultFileExtension = factory.DefaultFileExtension; 
 
                    key = plugIns.CreateSubKey(keyName);
                    sd.WriteToRegistryKey(key); 
                    key.Close();
                }
            }
            catch (KeyNotFoundException) 
            {
                sd = null; 
            } 

            if (sd != null) 
            {
                Assembly plugIn = Assembly.ReflectionOnlyLoadFrom(sd._assemblyPath);
                if (typeof(System.Windows.Controls.Button).Assembly.GetName().Version == sd._winFXVersion &&
                        plugIn != null && 
                        plugIn.GetName().Version == sd._assemblyVersion)
                { 
                    sd._isLoadable = true; 
                }
            } 

            return sd;
        }
        /// <summary>
        /// Create a SerializerWriter identified by the passed in SerializerDescriptor on the passed in stream
        /// </summary>
        /// <remarks> 
        ///     With a SerializerProvider (which requires full trust to ctor) and a SerializerDescriptor (which requires
        ///     full trust to obtain) create a SerializerWriter 
        /// 
        ///     This method currently requires full trust to run.
        /// </remarks> 
        ///<SecurityNote>
        ///  The DemandPlugInSerializerPermissions() ensures that this method only works in full trust.
        ///  Full trust is required, so that partial trust applications do not load or use potentially
        ///  unsafe serializer plug ins 
        ///</SecurityNote>
        public SerializerWriter CreateSerializerWriter(SerializerDescriptor serializerDescriptor, Stream stream) 
        { 
            SecurityHelper.DemandPlugInSerializerPermissions();
 
            SerializerWriter serializerWriter = null;

            if (serializerDescriptor == null)
            { 
                throw new ArgumentNullException("serializerDescriptor");
            } 
 
            string serializerKey = serializerDescriptor.DisplayName + "/" + serializerDescriptor.AssemblyName + "/" + serializerDescriptor.AssemblyVersion + "/" + serializerDescriptor.WinFXVersion;
 
            if (!serializerDescriptor.IsLoadable)
            {
                throw new ArgumentException(SR.Get(SRID.SerializerProviderWrongVersion), serializerKey);
            } 
            if (stream == null)
            { 
                throw new ArgumentNullException("stream"); 
            }
 
            bool found = false;
            foreach (SerializerDescriptor sd in InstalledSerializers)
            {
                if (sd.Equals(serializerDescriptor)) 
                {
                    found = true; 
                    break; 
                }
            } 

            if (!found)
            {
                throw new ArgumentException(SR.Get(SRID.SerializerProviderUnknownSerializer), serializerKey); 
            }
 
            try 
            {
                ISerializerFactory factory = serializerDescriptor.CreateSerializerFactory(); 

                serializerWriter = factory.CreateSerializerWriter(stream);
            }
            catch (FileNotFoundException) 
            {
                throw new ArgumentException(SR.Get(SRID.SerializerProviderCannotLoad), serializerDescriptor.DisplayName); 
            } 
            catch (FileLoadException)
            { 
                throw new ArgumentException(SR.Get(SRID.SerializerProviderCannotLoad), serializerDescriptor.DisplayName);
            }
            catch (BadImageFormatException)
            { 
                throw new ArgumentException(SR.Get(SRID.SerializerProviderCannotLoad), serializerDescriptor.DisplayName);
            } 
            catch (MissingMethodException) 
            {
                throw new ArgumentException(SR.Get(SRID.SerializerProviderCannotLoad), serializerDescriptor.DisplayName); 
            }

            return serializerWriter;
        }