private static void AddReferencedAssemblyInfo(AssemblyMetadataParser parser, AssemblyMetaData result)
 {
     try
     {
         // ToArray is required, otherwise sequence might be enumerated when context is already closed.
         var referencedAssemblyNames = parser.GetReferencedAssemblyNames().ToArray();
         result.SetReferencedAssemblyNames(referencedAssemblyNames);
     }
     catch
     {
         // Ignore if unable to fetch information.
     }
 }
        private static void AddAssemblyAttributes(AssemblyMetadataParser parser, AssemblyMetaData result)
        {
            try
            {
                foreach (var attribute in parser.GetAssemblyAttributes())
                {
                    var value = TryReadAttributeValue(attribute);
                    if (value == null)
                    {
                        continue;
                    }

                    var displayName = ReadAttributeDisplayName(attribute);
                    result.AddMetadata(displayName, value);
                }
            }
            catch (Exception)
            {
                // Silently abort the process if unable to fetch all the attributes.
            }
        }
        public static AssemblyMetaData ReadMetaData(string assemblyPath)
        {
            if (assemblyPath == null)
            {
                return(null);
            }

            var result = new AssemblyMetaData();

            var assemblyName = AssemblyName.GetAssemblyName(assemblyPath);

            if (assemblyName == null)
            {
                return(result);
            }

            result.SetFullName(assemblyName);

            // For WinRT component, we can only read Full Name.
            if (assemblyName.ContentType == AssemblyContentType.WindowsRuntime)
            {
                return(result);
            }

            try
            {
                using (var metadataParser = new AssemblyMetadataParser(assemblyPath))
                {
                    AddAssemblyAttributes(metadataParser, result);
                    AddReferencedAssemblyInfo(metadataParser, result);
                    result.DebugData = metadataParser.GetDebugData();
                }
            }
            catch
            {
                // Ingore if unable to read metadata.
            }

            return(result);
        }