Fix Assembly.LoadFromPartialName(string) (#23912)
authorSteve MacLean <stmaclea@microsoft.com>
Fri, 12 Apr 2019 03:48:59 +0000 (23:48 -0400)
committerGitHub <noreply@github.com>
Fri, 12 Apr 2019 03:48:59 +0000 (23:48 -0400)
Assembly.LoadFromPartialName(string) should not throw FileNotFoundException, but
should rather return null.

ArgumentException should use nameof(partialName)

Fixes #19817

src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs

index 3db428e..1e9699f 100644 (file)
@@ -205,7 +205,17 @@ namespace System.Reflection
             if (partialName == null)
                 throw new ArgumentNullException(nameof(partialName));
 
-            return Load(partialName);
+            if ((partialName.Length == 0) || (partialName[0] == '\0'))
+                throw new ArgumentException(SR.Format_StringZeroLength, nameof(partialName));
+
+            try
+            {
+                return Load(partialName);
+            }
+            catch (FileNotFoundException)
+            {
+                return null;
+            }
         }
 
         // Loads the assembly with a COFF based IMAGE containing