@@ -22,6 +22,8 @@ namespace Microsoft.Azure.WebJobs.Script.Description
22
22
/// </summary>
23
23
public partial class FunctionAssemblyLoadContext : AssemblyLoadContext
24
24
{
25
+ private const string PrivateDependencyResolutionPolicy = "private" ;
26
+
25
27
private static readonly Lazy < Dictionary < string , ScriptRuntimeAssembly > > _runtimeAssemblies = new Lazy < Dictionary < string , ScriptRuntimeAssembly > > ( DependencyHelper . GetRuntimeAssemblies ) ;
26
28
private static readonly Lazy < Dictionary < string , ResolutionPolicyEvaluator > > _resolutionPolicyEvaluators = new Lazy < Dictionary < string , ResolutionPolicyEvaluator > > ( InitializeLoadPolicyEvaluators ) ;
27
29
private static readonly ConcurrentDictionary < string , object > _sharedContextAssembliesInFallbackLoad = new ConcurrentDictionary < string , object > ( ) ;
@@ -128,7 +130,8 @@ private static Dictionary<string, ResolutionPolicyEvaluator> InitializeLoadPolic
128
130
return new Dictionary < string , ResolutionPolicyEvaluator >
129
131
{
130
132
{ "minorMatchOrLower" , IsMinorMatchOrLowerPolicyEvaluator } ,
131
- { "runtimeVersion" , RuntimeVersionPolicyEvaluator }
133
+ { "runtimeVersion" , RuntimeVersionPolicyEvaluator } ,
134
+ { PrivateDependencyResolutionPolicy , ( a , b ) => false }
132
135
} ;
133
136
}
134
137
@@ -194,31 +197,42 @@ protected override Assembly Load(AssemblyName assemblyName)
194
197
return assembly ;
195
198
}
196
199
197
- // If the assembly being requested matches a runtime assembly,
198
- // we'll use the runtime assembly instead of loading it in this context:
199
- if ( TryLoadRuntimeAssembly ( assemblyName , out assembly ) )
200
+ // If this is a runtime restricted assembly, load it based on unification rules
201
+ if ( TryGetRuntimeAssembly ( assemblyName , out ScriptRuntimeAssembly scriptRuntimeAssembly ) )
202
+ {
203
+ return LoadRuntimeAssembly ( assemblyName , scriptRuntimeAssembly ) ;
204
+ }
205
+
206
+ // If the assembly being requested matches a host assembly, we'll use
207
+ // the host assembly instead of loading it in this context:
208
+ if ( TryLoadHostEnvironmentAssembly ( assemblyName , out assembly ) )
200
209
{
201
210
return assembly ;
202
211
}
203
212
204
- if ( TryGetRuntimeAssembly ( assemblyName , out ScriptRuntimeAssembly scriptRuntimeAssembly ) )
213
+ return LoadCore ( assemblyName ) ;
214
+ }
215
+
216
+ private Assembly LoadRuntimeAssembly ( AssemblyName assemblyName , ScriptRuntimeAssembly scriptRuntimeAssembly )
217
+ {
218
+ // If this is a private runtime assembly, return function dependency
219
+ if ( string . Equals ( scriptRuntimeAssembly . ResolutionPolicy , PrivateDependencyResolutionPolicy ) )
205
220
{
206
- // If there was a failure loading a runtime assembly, ensure we gracefuly unify to
207
- // the runtime version of the assembly if the version falls within a safe range.
208
- if ( TryLoadRuntimeAssembly ( new AssemblyName ( assemblyName . Name ) , out assembly ) )
209
- {
210
- var policyEvaluator = GetResolutionPolicyEvaluator ( scriptRuntimeAssembly . ResolutionPolicy ) ;
221
+ return LoadCore ( assemblyName ) ;
222
+ }
211
223
212
- if ( policyEvaluator . Invoke ( assemblyName , assembly ) )
213
- {
214
- return assembly ;
215
- }
216
- }
224
+ // Attempt to load the runtime version of the assembly based on the unification policy evaluation result.
225
+ if ( TryLoadHostEnvironmentAssembly ( assemblyName , allowPartialNameMatch : true , out Assembly assembly ) )
226
+ {
227
+ var policyEvaluator = GetResolutionPolicyEvaluator ( scriptRuntimeAssembly . ResolutionPolicy ) ;
217
228
218
- return null ;
229
+ if ( policyEvaluator . Invoke ( assemblyName , assembly ) )
230
+ {
231
+ return assembly ;
232
+ }
219
233
}
220
234
221
- return LoadCore ( assemblyName ) ;
235
+ return null ;
222
236
}
223
237
224
238
private bool TryLoadDepsDependency ( AssemblyName assemblyName , out Assembly assembly )
@@ -279,7 +293,13 @@ internal static bool TryGetDepsAsset(IDictionary<string, RuntimeAsset[]> depsAss
279
293
return assemblyPath != null ;
280
294
}
281
295
282
- private bool TryLoadRuntimeAssembly ( AssemblyName assemblyName , out Assembly assembly )
296
+ private bool TryLoadHostEnvironmentAssembly ( AssemblyName assemblyName , bool allowPartialNameMatch , out Assembly assembly )
297
+ {
298
+ return TryLoadHostEnvironmentAssembly ( assemblyName , out assembly )
299
+ || ( allowPartialNameMatch && TryLoadHostEnvironmentAssembly ( new AssemblyName ( assemblyName . Name ) , out assembly ) ) ;
300
+ }
301
+
302
+ private bool TryLoadHostEnvironmentAssembly ( AssemblyName assemblyName , out Assembly assembly )
283
303
{
284
304
assembly = null ;
285
305
try
0 commit comments