Example #1
0
        [System.Security.SecurityCritical]  // auto-generated
        private void RegisterPrimaryInteropAssembly(RuntimeAssembly assembly, String strAsmCodeBase, PrimaryInteropAssemblyAttribute attr)
        {
            // Validate that the PIA has a strong name.
            if (assembly.GetPublicKey().Length == 0)
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_PIAMustBeStrongNamed"));

            String strTlbId = "{" + Marshal.GetTypeLibGuidForAssembly(assembly).ToString().ToUpper(CultureInfo.InvariantCulture) + "}";
            String strVersion = attr.MajorVersion.ToString("x", CultureInfo.InvariantCulture) + "." + attr.MinorVersion.ToString("x", CultureInfo.InvariantCulture);

            // Create the HKEY_CLASS_ROOT\TypeLib key.
            using (RegistryKey TypeLibRootKey = Registry.ClassesRoot.CreateSubKey(strTlbRootName))
            {
                // Create the HKEY_CLASS_ROOT\TypeLib\<TLBID> key.
                using (RegistryKey TypeLibKey = TypeLibRootKey.CreateSubKey(strTlbId))
                {
                    // Create the HKEY_CLASS_ROOT\TypeLib\<TLBID>\<Major.Minor> key.
                    using (RegistryKey VersionSubKey = TypeLibKey.CreateSubKey(strVersion))
                    {
                        // Create the HKEY_CLASS_ROOT\TypeLib\<TLBID>\PrimaryInteropAssembly key.
                        VersionSubKey.SetValue("PrimaryInteropAssemblyName", assembly.FullName);
                        if (strAsmCodeBase != null)
                            VersionSubKey.SetValue("PrimaryInteropAssemblyCodeBase", strAsmCodeBase);
                    }
                }
            }
        }
 private void RegisterPrimaryInteropAssembly(RuntimeAssembly assembly, string strAsmCodeBase, PrimaryInteropAssemblyAttribute attr)
 {
     if (assembly.GetPublicKey().Length == 0)
     {
         throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_PIAMustBeStrongNamed"));
     }
     string subkey = "{" + Marshal.GetTypeLibGuidForAssembly(assembly).ToString().ToUpper(CultureInfo.InvariantCulture) + "}";
     string str2 = attr.MajorVersion.ToString("x", CultureInfo.InvariantCulture) + "." + attr.MinorVersion.ToString("x", CultureInfo.InvariantCulture);
     using (RegistryKey key = Registry.ClassesRoot.CreateSubKey("TypeLib"))
     {
         using (RegistryKey key2 = key.CreateSubKey(subkey))
         {
             using (RegistryKey key3 = key2.CreateSubKey(str2))
             {
                 key3.SetValue("PrimaryInteropAssemblyName", assembly.FullName);
                 if (strAsmCodeBase != null)
                 {
                     key3.SetValue("PrimaryInteropAssemblyCodeBase", strAsmCodeBase);
                 }
             }
         }
     }
 }