private void RegisterPrimaryInteropAssembly(RuntimeAssembly assembly, string strAsmCodeBase, PrimaryInteropAssemblyAttribute attr)
        {
            if (assembly.GetPublicKey().Length == 0)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_PIAMustBeStrongNamed"));
            }
            string subkey1 = "{" + Marshal.GetTypeLibGuidForAssembly((Assembly)assembly).ToString().ToUpper(CultureInfo.InvariantCulture) + "}";
            string subkey2 = attr.MajorVersion.ToString("x", (IFormatProvider)CultureInfo.InvariantCulture) + "." + attr.MinorVersion.ToString("x", (IFormatProvider)CultureInfo.InvariantCulture);

            using (RegistryKey subKey1 = Registry.ClassesRoot.CreateSubKey("TypeLib"))
            {
                using (RegistryKey subKey2 = subKey1.CreateSubKey(subkey1))
                {
                    using (RegistryKey subKey3 = subKey2.CreateSubKey(subkey2))
                    {
                        subKey3.SetValue("PrimaryInteropAssemblyName", (object)assembly.FullName);
                        if (strAsmCodeBase == null)
                        {
                            return;
                        }
                        subKey3.SetValue("PrimaryInteropAssemblyCodeBase", (object)strAsmCodeBase);
                    }
                }
            }
        }
Example #2
0
 private void InitSafeToDeserializeArray()
 {
     this._safeToDeserialize = new bool[this._typeTable.Length];
     for (int index = 0; index < this._typeTable.Length; ++index)
     {
         long   position = this._store.BaseStream.Position;
         string typeName;
         try
         {
             this._store.BaseStream.Position = (long)this._typeNamePositions[index];
             typeName = this._store.ReadString();
         }
         finally
         {
             this._store.BaseStream.Position = position;
         }
         RuntimeType  runtimeType = (RuntimeType)Type.GetType(typeName, false);
         AssemblyName asmName2;
         string       typeName2;
         if (runtimeType == (RuntimeType)null)
         {
             asmName2  = (AssemblyName)null;
             typeName2 = typeName;
         }
         else
         {
             if (runtimeType.BaseType == typeof(Enum))
             {
                 this._safeToDeserialize[index] = true;
                 continue;
             }
             typeName2 = runtimeType.FullName;
             asmName2  = new AssemblyName();
             RuntimeAssembly runtimeAssembly = (RuntimeAssembly)runtimeType.Assembly;
             asmName2.Init(runtimeAssembly.GetSimpleName(), runtimeAssembly.GetPublicKey(), (byte[])null, (Version)null, runtimeAssembly.GetLocale(), AssemblyHashAlgorithm.None, AssemblyVersionCompatibility.SameMachine, (string)null, AssemblyNameFlags.PublicKey, (StrongNameKeyPair)null);
         }
         foreach (string asmTypeName1 in ResourceReader.TypesSafeForDeserialization)
         {
             if (ResourceManager.CompareNames(asmTypeName1, typeName2, asmName2))
             {
                 this._safeToDeserialize[index] = true;
             }
         }
     }
 }
 private void InitSafeToDeserializeArray()
 {
     this._safeToDeserialize = new bool[this._typeTable.Length];
     for (int i = 0; i < this._typeTable.Length; i++)
     {
         string       str;
         AssemblyName name;
         string       fullName;
         long         position = this._store.BaseStream.Position;
         try
         {
             this._store.BaseStream.Position = this._typeNamePositions[i];
             str = this._store.ReadString();
         }
         finally
         {
             this._store.BaseStream.Position = position;
         }
         RuntimeType type = (RuntimeType)Type.GetType(str, false);
         if (type == null)
         {
             name     = null;
             fullName = str;
         }
         else
         {
             if (type.BaseType == typeof(Enum))
             {
                 this._safeToDeserialize[i] = true;
                 continue;
             }
             fullName = type.FullName;
             name     = new AssemblyName();
             RuntimeAssembly assembly = (RuntimeAssembly)type.Assembly;
             name.Init(assembly.GetSimpleName(), assembly.GetPublicKey(), null, null, assembly.GetLocale(), AssemblyHashAlgorithm.None, AssemblyVersionCompatibility.SameMachine, null, AssemblyNameFlags.PublicKey, null);
         }
         foreach (string str3 in TypesSafeForDeserialization)
         {
             if (ResourceManager.CompareNames(str3, fullName, name))
             {
                 this._safeToDeserialize[i] = true;
             }
         }
     }
 }