Example #1
0
        public static bool IsCOMAssembly(Assembly a)
        {
            object[] AsmAttributes = a.GetCustomAttributes(typeof(ImportedFromTypeLibAttribute), true);
            if (AsmAttributes.Length > 0)
            {
                ImportedFromTypeLibAttribute imptlb = ( ImportedFromTypeLibAttribute )AsmAttributes[0];
                string strImportedFrom = imptlb.Value;

                // Print out the name of the DLL from which the assembly is imported.
                Console.WriteLine("Assembly " + a.FullName + " is imported from " + strImportedFrom);

                return(true);
            }
            // This is not a COM assembly.
            Console.WriteLine("Assembly " + a.FullName + " is not imported from COM");
            return(false);
        }
Example #2
0
        private static bool FillRcwReferences(ref int returnCode)
        {
            // Stash correspondence between typelib name and RCW dll.  Typelib
            // name found through assembly level attribute on the RCW dll.

            foreach (string rcwPartialPath in rcwOptions)
            {
                string rcwPath = Path.Combine(Environment.CurrentDirectory, rcwPartialPath);

                if (!File.Exists(rcwPath))
                {
                    WriteErrorMsg(AxImpSR.GetString(AxImpSR.Err_RefAssemblyNotFound, rcwPath));
                    returnCode = ErrorReturnCode;
                    return(false);
                }

                Assembly asm;
                try
                {
                    asm = Assembly.LoadFrom(rcwPath);
                }
                catch (Exception e)
                {
                    WriteErrorMsg(AxImpSR.GetString(AxImpSR.Err_AssemblyLoadFailed, rcwPath, e.Message));
                    returnCode = ErrorReturnCode;
                    return(false);
                }

                object [] attrs = asm.GetCustomAttributes(typeof(ImportedFromTypeLibAttribute), true);
                if (attrs.Length != 1)
                {
                    WriteErrorMsg(AxImpSR.GetString(AxImpSR.Err_NotRcw, rcwPath));
                    returnCode = ErrorReturnCode;
                    return(false);
                }

                ImportedFromTypeLibAttribute attr = (ImportedFromTypeLibAttribute)(attrs[0]);
                rcwReferences[attr.Value] = rcwPath;
            }

            return(true);
        }
        public void Ctor_TlbFile(string tlbFile)
        {
            var attribute = new ImportedFromTypeLibAttribute(tlbFile);

            Assert.Equal(tlbFile, attribute.Value);
        }