Example #1
0
        /// <summary>
        /// Register the assembly for COM interop
        /// </summary>
        /// <param name="stateSaver">An IDictionary used to save information
        /// needed to perform a commit, rollback, or uninstall operation.
        /// </param>
        public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);

            RegistrationServices regSrv = new RegistrationServices();

            System.Reflection.Assembly assembly = base.GetType().Assembly;

            AssemblyRegistrationFlags flags = AssemblyRegistrationFlags.SetCodeBase;

            regSrv.RegisterAssembly(assembly, flags);
        }
		public virtual bool RegisterAssembly (Assembly assembly, AssemblyRegistrationFlags flags)
		{
			throw new NotImplementedException ();
		}
Example #3
0
        [System.Security.SecurityCritical]  // auto-generated_required
        public virtual bool RegisterAssembly(Assembly assembly, AssemblyRegistrationFlags flags)
        {
            // Validate the arguments.
            if (assembly == null)
                throw new ArgumentNullException("assembly");

            if (assembly.ReflectionOnly)
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_AsmLoadedForReflectionOnly"));
            Contract.EndContractBlock();

            RuntimeAssembly rtAssembly = assembly as RuntimeAssembly;
            if (rtAssembly == null)
                throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"));

            // Retrieve the assembly names.
            String strAsmName = assembly.FullName;
            if (strAsmName == null)
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NoAsmName"));

            // Retrieve the assembly codebase.
            String strAsmCodeBase = null;
            if ((flags & AssemblyRegistrationFlags.SetCodeBase) != 0)
            {
                strAsmCodeBase = rtAssembly.GetCodeBase(false);
                if (strAsmCodeBase == null)
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NoAsmCodeBase"));
            }

            // Go through all the registerable types in the assembly and register them.
            Type[] aTypes = GetRegistrableTypesInAssembly(assembly);
            int NumTypes = aTypes.Length;

            String strAsmVersion = rtAssembly.GetVersion().ToString();
            
            // Retrieve the runtime version used to build the assembly.
            String strRuntimeVersion = assembly.ImageRuntimeVersion;

            for (int cTypes = 0; cTypes < NumTypes; cTypes++)
            {
                if (IsRegisteredAsValueType(aTypes[cTypes]))
                    RegisterValueType(aTypes[cTypes], strAsmName, strAsmVersion, strAsmCodeBase, strRuntimeVersion);
                else if (TypeRepresentsComType(aTypes[cTypes]))
                    RegisterComImportedType(aTypes[cTypes], strAsmName, strAsmVersion, strAsmCodeBase, strRuntimeVersion);
                else
                    RegisterManagedType(aTypes[cTypes], strAsmName, strAsmVersion, strAsmCodeBase, strRuntimeVersion);

                CallUserDefinedRegistrationMethod(aTypes[cTypes], true);
            }

            // If this assembly has the PIA attribute, then register it as a PIA.
            Object[] aPIAAttrs = assembly.GetCustomAttributes(typeof(PrimaryInteropAssemblyAttribute), false);
            int NumPIAAttrs = aPIAAttrs.Length;
            for (int cPIAAttrs = 0; cPIAAttrs < NumPIAAttrs; cPIAAttrs++)
                RegisterPrimaryInteropAssembly(rtAssembly, strAsmCodeBase, (PrimaryInteropAssemblyAttribute)aPIAAttrs[cPIAAttrs]);

            // Return value indicating if we actually registered any types.
            if (aTypes.Length > 0 || NumPIAAttrs > 0)
                return true;
            else 
                return false;
        }
 public virtual bool RegisterAssembly(Assembly assembly, AssemblyRegistrationFlags flags)
 {
     throw new NotImplementedException();
 }
Example #5
0
        public static int Run(RegAsmOptions options)
        {
            s_Options = options;

            int RetCode = SuccessReturnCode;

            try
            {
                // Load the assembly.
                Assembly asm = null;
                try
                {
                    asm = Assembly.LoadFrom(s_Options.m_strAssemblyName);
                }
                catch (BadImageFormatException)
                {
                    throw new ApplicationException(Resource.FormatString("Err_InvalidAssembly", s_Options.m_strAssemblyName));
                }
                catch (FileNotFoundException)
                {
                    throw new ApplicationException(Resource.FormatString("Err_InputFileNotFound", s_Options.m_strAssemblyName));
                }

                if (s_Options.m_strRegFileName != null)
                {
                    // Make sure the registry file will not overwrite the input file.
                    if (String.Compare(s_Options.m_strAssemblyName, s_Options.m_strRegFileName, true, CultureInfo.InvariantCulture) == 0)
                    {
                        throw new ApplicationException(Resource.FormatString("Err_RegFileWouldOverwriteInput"));
                    }

                    // If /codebase is specified, then give a warning if the assembly is not strongly
                    // named.
                    if (s_Options.m_bSetCodeBase && asm.GetName().GetPublicKey() == null || s_Options.m_bSetCodeBase && asm.GetName().GetPublicKey().Length == 0)
                    {
                        WriteWarningMsg(Resource.FormatString("Wrn_CodeBaseWithNoStrongName"));
                    }

                    // The user wants to generate a reg file.
                    bool bRegFileGenerated = GenerateRegFile(s_Options.m_strRegFileName, asm);
                    if (!s_Options.m_bSilentMode)
                    {
                        if (bRegFileGenerated)
                        {
                            Console.WriteLine(Resource.FormatString("Msg_RegScriptGenerated", s_Options.m_strRegFileName));
                        }
                        else
                        {
                            WriteWarningMsg(Resource.FormatString("Wrn_NoRegScriptGenerated"));
                        }
                    }
                }
                else if (s_Options.m_bRegister)
                {
                    // If /codebase is specified, then give a warning if the assembly is not strongly
                    // named.
                    if (s_Options.m_bSetCodeBase && asm.GetName().GetPublicKey() == null || s_Options.m_bSetCodeBase && asm.GetName().GetPublicKey().Length == 0)
                    {
                        WriteWarningMsg(Resource.FormatString("Wrn_CodeBaseWithNoStrongName"));
                    }

                    // Register the types inside the assembly.
                    AssemblyRegistrationFlags flags = s_Options.m_bSetCodeBase ? AssemblyRegistrationFlags.SetCodeBase : 0;
                    bool bTypesRegistered           = s_RegistrationServices.RegisterAssembly(asm, flags);
                    if (!s_Options.m_bSilentMode)
                    {
                        if (bTypesRegistered)
                        {
                            Console.WriteLine(Resource.FormatString("Msg_TypesRegistered"));
                        }
                        else
                        {
                            WriteWarningMsg(Resource.FormatString("Wrn_NoTypesRegistered"));
                        }
                    }

                    // Register the typelib if the /tlb option is specified.
                    if (s_Options.m_strTypeLibName != null)
                    {
                        RegisterMainTypeLib(asm);
                    }
                }
                else
                {
                    // Unregister the types inside the assembly.
                    bool bTypesUnregistered = s_RegistrationServices.UnregisterAssembly(asm);
                    if (!s_Options.m_bSilentMode)
                    {
                        if (bTypesUnregistered)
                        {
                            Console.WriteLine(Resource.FormatString("Msg_TypesUnRegistered"));
                        }
                        else
                        {
                            WriteWarningMsg(Resource.FormatString("Wrn_NoTypesUnRegistered"));
                        }
                    }

                    // Un-register the typelib if the /tlb option is specified.
                    if (s_Options.m_strTypeLibName != null)
                    {
                        // Check to see if the assembly is imported from COM.
                        if (IsAssemblyImportedFromCom(asm))
                        {
                            if (!s_Options.m_bSilentMode)
                            {
                                WriteWarningMsg(Resource.FormatString("Wrn_ComTypelibNotUnregistered"));
                            }
                        }
                        else
                        {
                            // Unregister the typelib.
                            UnRegisterMainTypeLib();
                        }
                    }
                }
            }
            catch (TargetInvocationException e)
            {
                WriteErrorMsg(Resource.FormatString("Err_ErrorInUserDefFunc") + e.InnerException);
                RetCode = ErrorReturnCode;
            }
            catch (ReflectionTypeLoadException e)
            {
                int         i;
                Exception[] exceptions;
                WriteErrorMsg(Resource.FormatString("Err_TypeLoadExceptions"));
                exceptions = e.LoaderExceptions;
                for (i = 0; i < exceptions.Length; i++)
                {
                    try
                    {
                        Console.Error.WriteLine(Resource.FormatString("Msg_DisplayException", i, exceptions[i]));
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine(Resource.FormatString("Msg_DisplayNestedException", i, ex));
                    }
                }
                RetCode = ErrorReturnCode;
            }
            catch (Exception e)
            {
                WriteErrorMsg(null, e);
                RetCode = ErrorReturnCode;
            }

            return(RetCode);
        }
 // Methods
 public virtual bool RegisterAssembly(System.Reflection.Assembly assembly, AssemblyRegistrationFlags flags)
 {
 }
Example #7
0
        public virtual bool RegisterAssembly(Assembly assembly, AssemblyRegistrationFlags flags)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }
            if (assembly.ReflectionOnly)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_AsmLoadedForReflectionOnly"));
            }
            RuntimeAssembly runtimeAssembly = assembly as RuntimeAssembly;

            if (runtimeAssembly == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"));
            }
            string fullName = assembly.FullName;

            if (fullName == null)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NoAsmName"));
            }
            string text = null;

            if ((flags & AssemblyRegistrationFlags.SetCodeBase) != AssemblyRegistrationFlags.None)
            {
                text = runtimeAssembly.GetCodeBase(false);
                if (text == null)
                {
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NoAsmCodeBase"));
                }
            }
            Type[] registrableTypesInAssembly = this.GetRegistrableTypesInAssembly(assembly);
            int    num                 = registrableTypesInAssembly.Length;
            string strAsmVersion       = runtimeAssembly.GetVersion().ToString();
            string imageRuntimeVersion = assembly.ImageRuntimeVersion;

            for (int i = 0; i < num; i++)
            {
                if (this.IsRegisteredAsValueType(registrableTypesInAssembly[i]))
                {
                    this.RegisterValueType(registrableTypesInAssembly[i], fullName, strAsmVersion, text, imageRuntimeVersion);
                }
                else if (this.TypeRepresentsComType(registrableTypesInAssembly[i]))
                {
                    this.RegisterComImportedType(registrableTypesInAssembly[i], fullName, strAsmVersion, text, imageRuntimeVersion);
                }
                else
                {
                    this.RegisterManagedType(registrableTypesInAssembly[i], fullName, strAsmVersion, text, imageRuntimeVersion);
                }
                this.CallUserDefinedRegistrationMethod(registrableTypesInAssembly[i], true);
            }
            object[] customAttributes = assembly.GetCustomAttributes(typeof(PrimaryInteropAssemblyAttribute), false);
            int      num2             = customAttributes.Length;

            for (int j = 0; j < num2; j++)
            {
                this.RegisterPrimaryInteropAssembly(runtimeAssembly, text, (PrimaryInteropAssemblyAttribute)customAttributes[j]);
            }
            return(registrableTypesInAssembly.Length != 0 || num2 > 0);
        }
        /// <include file='doc\RegistrationServices.uex' path='docs/doc[@for="RegistrationServices.RegisterAssembly"]/*' />
        public virtual bool RegisterAssembly(Assembly assembly, AssemblyRegistrationFlags flags)
        {
            // Validate the arguments.
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            // Retrieve the assembly names.
            String strAsmName = assembly.FullName;

            if (strAsmName == null)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NoAsmName"));
            }

            // Retrieve the assembly version
            String strAsmVersion = assembly.GetName().Version.ToString();

            // Retrieve the runtime version used to build the assembly.
            String strRuntimeVersion = assembly.ImageRuntimeVersion;

            // Retrieve the assembly codebase.
            String strAsmCodeBase = null;

            if ((flags & AssemblyRegistrationFlags.SetCodeBase) != 0)
            {
                strAsmCodeBase = assembly.CodeBase;
                if (strAsmCodeBase == null)
                {
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NoAsmCodeBase"));
                }
            }

            // Go through all the registrable types in the assembly and register them.
            Type[] aTypes   = GetRegistrableTypesInAssembly(assembly);
            int    NumTypes = aTypes.Length;

            for (int cTypes = 0; cTypes < NumTypes; cTypes++)
            {
                if (aTypes[cTypes].IsValueType)
                {
                    RegisterValueType(aTypes[cTypes], strAsmName, strAsmVersion, strAsmCodeBase);
                }
                else if (TypeRepresentsComType(aTypes[cTypes]))
                {
                    RegisterComImportedType(aTypes[cTypes], strAsmName, strAsmVersion, strAsmCodeBase, strRuntimeVersion);
                }
                else
                {
                    RegisterManagedType(aTypes[cTypes], strAsmName, strAsmVersion, strAsmCodeBase, strRuntimeVersion);
                }

                CallUserDefinedRegistrationMethod(aTypes[cTypes], true);
            }

            // If this assembly has the PIA attribute, then register it as a PIA.
            Object[] aPIAAttrs   = assembly.GetCustomAttributes(typeof(PrimaryInteropAssemblyAttribute), false);
            int      NumPIAAttrs = aPIAAttrs.Length;

            for (int cPIAAttrs = 0; cPIAAttrs < NumPIAAttrs; cPIAAttrs++)
            {
                RegisterPrimaryInteropAssembly(assembly, strAsmCodeBase, (PrimaryInteropAssemblyAttribute)aPIAAttrs[cPIAAttrs]);
            }

            // Return value indicating if we actually registered any types.
            if (aTypes.Length > 0 || NumPIAAttrs > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #9
0
 public virtual new bool RegisterAssembly(System.Reflection.Assembly assembly, AssemblyRegistrationFlags flags)
 {
     return(default(bool));
 }
 public bool RegisterAssembly (System.Reflection.Assembly! assembly, AssemblyRegistrationFlags flags) {
     CodeContract.Requires(assembly != null);
   return default(bool);
 }
 public virtual new bool RegisterAssembly(System.Reflection.Assembly assembly, AssemblyRegistrationFlags flags)
 {
   return default(bool);
 }
 public bool RegisterAssembly(System.Reflection.Assembly assembly, AssemblyRegistrationFlags flags)
 {
     Contract.Requires(assembly != null);
     return(default(bool));
 }
 public virtual bool RegisterAssembly(Assembly assembly, AssemblyRegistrationFlags flags)
 {
     if (assembly == null)
     {
         throw new ArgumentNullException("assembly");
     }
     if (assembly.ReflectionOnly)
     {
         throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_AsmLoadedForReflectionOnly"));
     }
     RuntimeAssembly assembly2 = assembly as RuntimeAssembly;
     if (assembly2 == null)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"));
     }
     string fullName = assembly.FullName;
     if (fullName == null)
     {
         throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NoAsmName"));
     }
     string strAsmCodeBase = null;
     if ((flags & AssemblyRegistrationFlags.SetCodeBase) != AssemblyRegistrationFlags.None)
     {
         strAsmCodeBase = assembly2.GetCodeBase(false);
         if (strAsmCodeBase == null)
         {
             throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NoAsmCodeBase"));
         }
     }
     Type[] registrableTypesInAssembly = this.GetRegistrableTypesInAssembly(assembly);
     int length = registrableTypesInAssembly.Length;
     string strAsmVersion = assembly2.GetVersion().ToString();
     string imageRuntimeVersion = assembly.ImageRuntimeVersion;
     for (int i = 0; i < length; i++)
     {
         if (this.IsRegisteredAsValueType(registrableTypesInAssembly[i]))
         {
             this.RegisterValueType(registrableTypesInAssembly[i], fullName, strAsmVersion, strAsmCodeBase, imageRuntimeVersion);
         }
         else if (this.TypeRepresentsComType(registrableTypesInAssembly[i]))
         {
             this.RegisterComImportedType(registrableTypesInAssembly[i], fullName, strAsmVersion, strAsmCodeBase, imageRuntimeVersion);
         }
         else
         {
             this.RegisterManagedType(registrableTypesInAssembly[i], fullName, strAsmVersion, strAsmCodeBase, imageRuntimeVersion);
         }
         this.CallUserDefinedRegistrationMethod(registrableTypesInAssembly[i], true);
     }
     object[] customAttributes = assembly.GetCustomAttributes(typeof(PrimaryInteropAssemblyAttribute), false);
     int num3 = customAttributes.Length;
     for (int j = 0; j < num3; j++)
     {
         this.RegisterPrimaryInteropAssembly(assembly2, strAsmCodeBase, (PrimaryInteropAssemblyAttribute) customAttributes[j]);
     }
     if ((registrableTypesInAssembly.Length <= 0) && (num3 <= 0))
     {
         return false;
     }
     return true;
 }
Example #14
0
 // Methods
 public virtual bool RegisterAssembly(System.Reflection.Assembly assembly, AssemblyRegistrationFlags flags)
 {
 }