dotnet-pgo: ignore native libs passed via -r *.dll (#56168)
authorEgor Bogatov <egorbo@gmail.com>
Sat, 24 Jul 2021 08:28:21 +0000 (11:28 +0300)
committerGitHub <noreply@github.com>
Sat, 24 Jul 2021 08:28:21 +0000 (11:28 +0300)
src/coreclr/tools/dotnet-pgo/Program.cs

index 32b4239..f129fdf 100644 (file)
@@ -999,13 +999,23 @@ namespace Microsoft.Diagnostics.Tools.Pgo
                 {
                     foreach (FileInfo fileReference in commandLineOptions.Reference)
                     {
-                        if (!File.Exists(fileReference.FullName))
+                        try
+                        {
+                            if (!File.Exists(fileReference.FullName))
+                            {
+                                PrintError($"Unable to find reference '{fileReference.FullName}'");
+                                filePathError = true;
+                            }
+                            else
+                                tsc.GetModuleFromPath(fileReference.FullName);
+                        }
+                        catch (Internal.TypeSystem.TypeSystemException.BadImageFormatException)
                         {
-                            PrintError($"Unable to find reference '{fileReference.FullName}'");
-                            filePathError = true;
+                            // Ignore BadImageFormat in order to allow users to use '-r *.dll'
+                            // in a folder with native dynamic libraries (which have the same extension on Windows).
+
+                            // We don't need to log a warning here - it's already logged in GetModuleFromPath
                         }
-                        else
-                            tsc.GetModuleFromPath(fileReference.FullName);
                     }
                 }