@@ -1256,26 +1256,40 @@ ICLRPrivBinder* AssemblySpec::GetBindingContextFromParentAssembly(AppDomain *pDo
1256
1256
1257
1257
// ICLRPrivAssembly implements ICLRPrivBinder and thus, "is a" binder in a manner of semantics.
1258
1258
pParentAssemblyBinder = pParentPEAssembly->GetBindingContext ();
1259
-
1259
+ }
1260
+
1260
1261
#if defined(FEATURE_HOST_ASSEMBLY_RESOLVER)
1261
- if (pParentAssemblyBinder != NULL )
1262
+ if (pParentAssemblyBinder == NULL )
1263
+ {
1264
+ // If the parent assembly binder is not available, then we maybe dealing with one of the following
1265
+ // assembly scenarios:
1266
+ //
1267
+ // 1) Domain Neutral assembly
1268
+ // 2) RefEmitted assembly
1269
+ // 3) Entrypoint assembly
1270
+ //
1271
+ // For (1) and (3), we will need to bind against the DefaultContext binder (aka TPA Binder). This happens
1272
+ // below if we do not find the parent assembly binder.
1273
+ //
1274
+ // For (2), check if we have the fallback load context binder for the requesting dynamic assembly available.
1275
+
1276
+ pParentAssemblyBinder = GetFallbackLoadContextBinderForRequestingAssembly ();
1277
+ }
1278
+
1279
+ if (pParentAssemblyBinder != NULL )
1280
+ {
1281
+ CLRPrivBinderCoreCLR *pTPABinder = pDomain->GetTPABinderContext ();
1282
+ if (AreSameBinderInstance (pTPABinder, pParentAssemblyBinder))
1262
1283
{
1263
- CLRPrivBinderCoreCLR *pTPABinder = pDomain->GetTPABinderContext ();
1264
- if (AreSameBinderInstance (pTPABinder, pParentAssemblyBinder))
1265
- {
1266
- // If the parent assembly is a platform (TPA) assembly, then its binding context will always be the TPABinder context. In
1267
- // such case, we will return the default context for binding to allow the bind to go
1268
- // via the custom binder context, if it was overridden. If it was not overridden, then we will get the expected
1269
- // TPABinder context anyways.
1270
- //
1271
- // Get the reference to the default binding context (this could be the TPABinder context or custom AssemblyLoadContext)
1272
- pParentAssemblyBinder = static_cast <ICLRPrivBinder*>(pDomain->GetFusionContext ());
1273
- }
1284
+ // If the parent assembly is a platform (TPA) assembly, then its binding context will always be the TPABinder context. In
1285
+ // such case, we will return the default context for binding to allow the bind to go
1286
+ // via the custom binder context, if it was overridden. If it was not overridden, then we will get the expected
1287
+ // TPABinder context anyways.
1288
+ //
1289
+ // Get the reference to the default binding context (this could be the TPABinder context or custom AssemblyLoadContext)
1290
+ pParentAssemblyBinder = static_cast <ICLRPrivBinder*>(pDomain->GetFusionContext ());
1274
1291
}
1275
- #endif // defined(FEATURE_HOST_ASSEMBLY_RESOLVER)
1276
1292
}
1277
-
1278
- #if defined(FEATURE_HOST_ASSEMBLY_RESOLVER)
1279
1293
1280
1294
#if defined(FEATURE_COMINTEROP)
1281
1295
if (!IsContentType_WindowsRuntime () && (pParentAssemblyBinder != NULL ))
@@ -1295,10 +1309,10 @@ ICLRPrivBinder* AssemblySpec::GetBindingContextFromParentAssembly(AppDomain *pDo
1295
1309
1296
1310
if (!pParentAssemblyBinder)
1297
1311
{
1298
- // We can be here when loading assemblies via the host (e.g. ICLRRuntimeHost2::ExecuteAssembly) or when attempting
1299
- // to load assemblies via custom AssemblyLoadContext implementation.
1312
+ // We can be here when loading assemblies via the host (e.g. ICLRRuntimeHost2::ExecuteAssembly) or dealing with assemblies
1313
+ // whose parent is a domain neutral assembly (see comment above for details).
1300
1314
//
1301
- // In such a case, the parent assembly (semantically) is mscorlib and thus, the default binding context should be
1315
+ // In such a case, the parent assembly (semantically) is CoreLibrary and thus, the default binding context should be
1302
1316
// used as the parent assembly binder.
1303
1317
pParentAssemblyBinder = static_cast <ICLRPrivBinder*>(pDomain->GetFusionContext ());
1304
1318
}
0 commit comments