@@ -110,16 +110,15 @@ private static void AssemblyLoadHandler(object ob, AssemblyLoadEventArgs args)
110
110
/// </summary>
111
111
private static Assembly ResolveHandler ( object ob , ResolveEventArgs args )
112
112
{
113
- string name = args . Name . ToLower ( ) ;
114
- foreach ( Assembly a in assemblies )
113
+ var name = new AssemblyName ( args . Name ) ;
114
+ foreach ( var alreadyLoaded in assemblies )
115
115
{
116
- string full = a . FullName . ToLower ( ) ;
117
- if ( full . StartsWith ( name ) )
116
+ if ( AssemblyName . ReferenceMatchesDefinition ( name , alreadyLoaded . GetName ( ) ) )
118
117
{
119
- return a ;
118
+ return alreadyLoaded ;
120
119
}
121
120
}
122
- return LoadAssemblyPath ( args . Name ) ;
121
+ return LoadAssemblyPath ( name . Name ) ;
123
122
}
124
123
125
124
@@ -154,6 +153,17 @@ internal static void UpdatePath()
154
153
}
155
154
}
156
155
156
+ /// <summary>
157
+ /// Given an assembly name, try to find this assembly file using the
158
+ /// PYTHONPATH. If not found, return null to indicate implicit load
159
+ /// using standard load semantics (app base directory then GAC, etc.)
160
+ /// </summary>
161
+ public static string FindAssembly ( AssemblyName name )
162
+ {
163
+ if ( name is null ) throw new ArgumentNullException ( nameof ( name ) ) ;
164
+
165
+ return FindAssembly ( name . Name ) ;
166
+ }
157
167
158
168
/// <summary>
159
169
/// Given an assembly name, try to find this assembly file using the
@@ -162,8 +172,13 @@ internal static void UpdatePath()
162
172
/// </summary>
163
173
public static string FindAssembly ( string name )
164
174
{
165
- char sep = Path . DirectorySeparatorChar ;
175
+ if ( name is null ) throw new ArgumentNullException ( nameof ( name ) ) ;
166
176
177
+ return FindAssemblyCandidates ( name ) . FirstOrDefault ( ) ;
178
+ }
179
+
180
+ static IEnumerable < string > FindAssemblyCandidates ( string name )
181
+ {
167
182
foreach ( string head in pypath )
168
183
{
169
184
string path ;
@@ -173,22 +188,21 @@ public static string FindAssembly(string name)
173
188
}
174
189
else
175
190
{
176
- path = head + sep + name ;
191
+ path = Path . Combine ( head , name ) ;
177
192
}
178
193
179
194
string temp = path + ".dll" ;
180
195
if ( File . Exists ( temp ) )
181
196
{
182
- return temp ;
197
+ yield return temp ;
183
198
}
184
199
185
200
temp = path + ".exe" ;
186
201
if ( File . Exists ( temp ) )
187
202
{
188
- return temp ;
203
+ yield return temp ;
189
204
}
190
205
}
191
- return null ;
192
206
}
193
207
194
208
0 commit comments