LoadFromResolve event handler should return null incase of any load error (#12329)
authorGaurav Khanna <gkhanna@microsoft.com>
Sat, 17 Jun 2017 00:26:11 +0000 (17:26 -0700)
committerGitHub <noreply@github.com>
Sat, 17 Jun 2017 00:26:11 +0000 (17:26 -0700)
src/mscorlib/src/System/Reflection/Assembly.CoreCLR.cs

index 68a4aa0..bbbd80b 100644 (file)
@@ -51,7 +51,19 @@ namespace System.Reflection
             string requestedAssemblyPath = Path.Combine(Path.GetDirectoryName(requestorPath), requestedAssemblyName.Name+".dll");
 
             // Load the dependency via LoadFrom so that it goes through the same path of being in the LoadFrom list.
-            return Assembly.LoadFrom(requestedAssemblyPath);
+            Assembly resolvedAssembly = null;
+
+            try
+            {
+                resolvedAssembly = Assembly.LoadFrom(requestedAssemblyPath);
+            }
+            catch(FileNotFoundException)
+            {
+                // Catch FileNotFoundException when attempting to resolve assemblies via this handler to account for missing assemblies.
+                resolvedAssembly = null;
+            }
+
+            return resolvedAssembly;
         }
 
         public static Assembly LoadFrom(String assemblyFile)