| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 497c22a commit fc989d5
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,7 @@ | |||
| 1 | 1 | using System; | |
| 2 | 2 | using System.IO; | |
| 3 | + using System.Runtime.InteropServices; | ||
| 4 | + | ||
| 3 | 5 | using NUnit.Framework; | |
| 4 | 6 | using Python.Runtime; | |
| 5 | 7 | ||
@@ -83,10 +85,18 @@ public void TestCastGlobalVar() | |||
| 83 | 85 | public void BadAssembly() | |
| 84 | 86 | { | |
| 85 | 87 | string path; | |
| 86 | - if (Python.Runtime.Runtime.IsWindows) | ||
| 88 | + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| 87 | 89 | { | |
| 88 | 90 | path = @"C:\Windows\System32\kernel32.dll"; | |
| 89 | 91 | } | |
| 92 | + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) | ||
| 93 | + { | ||
| 94 | + path = "/usr/lib/libc.dylib"; | ||
| 95 | + } | ||
| 96 | + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | ||
| 97 | + { | ||
| 98 | + path = "/usr/lib/locale/locale-archive"; | ||
| 99 | + } | ||
| 90 | 100 | else | |
| 91 | 101 | { | |
| 92 | 102 | Assert.Pass("TODO: add bad assembly location for other platforms"); | |
@@ -98,7 +108,7 @@ import clr | |||
| 98 | 108 | clr.AddReference('{path}') | |
| 99 | 109 | "; | |
| 100 | 110 | ||
| 101 | - Assert.Throws<FileLoadException>(() => PythonEngine.Exec(code)); | ||
| 111 | + Assert.Throws<BadImageFormatException>(() => PythonEngine.Exec(code)); | ||
| 102 | 112 | } | |
| 103 | 113 | } | |
| 104 | 114 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -121,6 +121,18 @@ private static Assembly ResolveHandler(object ob, ResolveEventArgs args) | |||
| 121 | 121 | return LoadAssemblyPath(name.Name); | |
| 122 | 122 | } | |
| 123 | 123 | ||
| 124 | + internal static AssemblyName? TryParseAssemblyName(string name) | ||
| 125 | + { | ||
| 126 | + try | ||
| 127 | + { | ||
| 128 | + return new AssemblyName(name); | ||
| 129 | + } | ||
| 130 | + catch (FileLoadException) | ||
| 131 | + { | ||
| 132 | + return null; | ||
| 133 | + } | ||
| 134 | + } | ||
| 135 | + | ||
| 124 | 136 | ||
| 125 | 137 | /// <summary> | |
| 126 | 138 | /// We __really__ want to avoid using Python objects or APIs when | |
@@ -208,18 +220,11 @@ static IEnumerable<string> FindAssemblyCandidates(string name) | |||
| 208 | 220 | ||
| 209 | 221 | /// <summary> | |
| 210 | 222 | /// Loads an assembly from the application directory or the GAC | |
| 211 | - /// given a simple assembly name. Returns the assembly if loaded. | ||
| 223 | + /// given its name. Returns the assembly if loaded. | ||
| 212 | 224 | /// </summary> | |
| 213 | - public static Assembly LoadAssembly(string name) | ||
| 225 | + public static Assembly LoadAssembly(AssemblyName name) | ||
| 214 | 226 | { | |
| 215 | - try | ||
| 216 | - { | ||
| 217 | - return Assembly.Load(name); | ||
| 218 | - } | ||
| 219 | - catch (FileNotFoundException) | ||
| 220 | - { | ||
| 221 | - return null; | ||
| 222 | - } | ||
| 227 | + return Assembly.Load(name); | ||
| 223 | 228 | } | |
| 224 | 229 | ||
| 225 | 230 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -516,9 +516,9 @@ public static Assembly AddReference(string name) | |||
| 516 | 516 | { | |
| 517 | 517 | assembly = AssemblyManager.LoadAssemblyPath(name); | |
| 518 | 518 | } | |
| 519 | - if (assembly == null) | ||
| 519 | + if (assembly == null && AssemblyManager.TryParseAssemblyName(name) is { } parsedName) | ||
| 520 | 520 | { | |
| 521 | - assembly = AssemblyManager.LoadAssembly(name); | ||
| 521 | + assembly = AssemblyManager.LoadAssembly(parsedName); | ||
| 522 | 522 | } | |
| 523 | 523 | if (assembly == null) | |
| 524 | 524 | { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments