private static AssemblyInfo GetAssemblyInfo(Stream assemblyStream, string assemblyLocation)
        {
            try
            {
                using (PEReader peReader = new PEReader(assemblyStream))
                {
                    bool isExe = peReader.PEHeaders?.IsExe ?? false;
                    bool isDll = peReader.PEHeaders?.IsDll ?? false;
                    bool isConsoleApplication = peReader.PEHeaders?.IsConsoleApplication ?? false;

                    if (!peReader.HasMetadata)
                    {
                        return(new AssemblyInfo(false, null, null, null, null, isExe, isDll, isConsoleApplication));
                    }

                    MetadataReader metadata = peReader.GetMetadataReader();


                    List <AssemblyName> references = new List <AssemblyName>();
                    foreach (var reference in metadata.AssemblyReferences.Select(metadata.GetAssemblyReference))
                    {
                        AssemblyName referenceAssemblyName = metadata.ParseAssemblyName(reference);
                        references.Add(referenceAssemblyName);
                    }

                    var           attr = metadata.FindAssemblyAttribute(KnownAttributes.TargetFrameworkAttribute, s_knownEnumTypes);
                    FrameworkName fnn  = null;
                    if (attr != null)
                    {
                        var fnns = attr.Value.FixedArguments[0].Value as string;
                        fnn = new FrameworkName(fnns);
                    }

                    AssemblyDefinition assemblyDefinition = metadata.GetAssemblyDefinition();
                    AssemblyName       assemblyName       = metadata.ParseAssemblyName(assemblyDefinition);
                    if (assemblyLocation != null)
                    {
                        assemblyName.CodeBase = FilePathToFileUrl(assemblyLocation);
                    }

                    return(new AssemblyInfo(metadata.IsAssembly, assemblyName, references, fnn, metadata.MetadataVersion, isExe, isDll, isConsoleApplication));
                }
            }
            catch (BadImageFormatException)
            {
                return(new AssemblyInfo(false, null, null, null, null, false, false, false));
            }
        }