private static CompilationDiff?ValidateFile(FileInfo originalBinary, BuildConstructor buildConstructor, ILogger logger, Options options) { if (s_ignorePatterns.Any(r => r.IsMatch(originalBinary.FullName))) { logger.LogTrace($"Ignoring {originalBinary.FullName}"); return(null); } MetadataReaderProvider?pdbReaderProvider = null; try { // Find the embedded pdb using var originalBinaryStream = originalBinary.OpenRead(); using var originalPeReader = new PEReader(originalBinaryStream); var pdbOpened = originalPeReader.TryOpenAssociatedPortablePdb( peImagePath: originalBinary.FullName, filePath => File.Exists(filePath) ? File.OpenRead(filePath) : null, out pdbReaderProvider, out var pdbPath); if (!pdbOpened || pdbReaderProvider is null) { logger.LogError($"Could not find pdb for {originalBinary.FullName}"); return(null); } using var _ = logger.BeginScope($"Verifying {originalBinary.FullName} with pdb {pdbPath ?? "[embedded]"}"); var pdbReader = pdbReaderProvider.GetMetadataReader(); var optionsReader = new CompilationOptionsReader(logger, pdbReader, originalPeReader); var compilation = buildConstructor.CreateCompilation( optionsReader, Path.GetFileNameWithoutExtension(originalBinary.Name)); var compilationDiff = CompilationDiff.Create(originalBinary, optionsReader, compilation, getDebugEntryPoint(), logger, options); return(compilationDiff); IMethodSymbol?getDebugEntryPoint() { if (optionsReader.GetMainTypeName() is { } mainTypeName&& optionsReader.GetMainMethodName() is { } mainMethodName) { var typeSymbol = compilation.GetTypeByMetadataName(mainTypeName); if (typeSymbol is object) { var methodSymbols = typeSymbol .GetMembers(mainMethodName) .OfType <IMethodSymbol>(); return(methodSymbols.FirstOrDefault()); } } return(null); } } finally { pdbReaderProvider?.Dispose(); } }