Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit daa688d

Browse files
authored
Fix Assembly.LoadFromPartialName(string) (#23912)
Assembly.LoadFromPartialName(string) should not throw FileNotFoundException, but should rather return null. ArgumentException should use nameof(partialName) Fixes #19817
1 parent 2a46c25 commit daa688d

File tree

1 file changed

+11
-1
lines changed
  • src/System.Private.CoreLib/shared/System/Reflection

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,17 @@ public static Assembly LoadWithPartialName(string partialName)
205205
if (partialName == null)
206206
throw new ArgumentNullException(nameof(partialName));
207207

208-
return Load(partialName);
208+
if ((partialName.Length == 0) || (partialName[0] == '\0'))
209+
throw new ArgumentException(SR.Format_StringZeroLength, nameof(partialName));
210+
211+
try
212+
{
213+
return Load(partialName);
214+
}
215+
catch (FileNotFoundException)
216+
{
217+
return null;
218+
}
209219
}
210220

211221
// Loads the assembly with a COFF based IMAGE containing

0 commit comments

Comments
 (0)