diff options
author | Koundinya Veluri <kouvel@microsoft.com> | 2015-11-10 10:35:30 -0800 |
---|---|---|
committer | Koundinya Veluri <kouvel@microsoft.com> | 2015-11-11 11:43:28 -0800 |
commit | 6a617fbd6296352fa1041bdf5efe02da1a41b9a7 (patch) | |
tree | 78a8b5a79f085abc1548667221ff252bb20c639a | |
parent | 077d5cb53bf9c0339cca6e2dc64e1d523987098d (diff) | |
download | coreclr-6a617fbd6296352fa1041bdf5efe02da1a41b9a7.tar.gz coreclr-6a617fbd6296352fa1041bdf5efe02da1a41b9a7.tar.bz2 coreclr-6a617fbd6296352fa1041bdf5efe02da1a41b9a7.zip |
Fix a couple of issues involving assembly loading
Fixes #1740
- After an assembly is loaded through a custom load context, when its dependencies are being loaded and the dependencies are in an app folder but not on the TPA list, don't search app paths when using the TPA binder, and instead use the default binder for the dependent assembly to load dependencies through the same custom AssemblyLoadContext.
Fixes #1187
- In the AssemblyName created by AssemblyLoadContext.GetAssemblyName(), don't initialize the CodeBase property since it's not in the exposed surface area for .NET Core. If the AssemblyName is passed to Assembly.Load(), note that regardless of the path sent to GetAssemblyName(), default search orders are still used to load the assembly by name. A custom AssemblyLoadContext would need to be used to control where an assembly is loaded from.
- Fixed a couple of error messages that mentioned phone
-rw-r--r-- | src/binder/assemblybinder.cpp | 18 | ||||
-rw-r--r-- | src/binder/binderinterface.cpp | 1 | ||||
-rw-r--r-- | src/binder/clrprivbinderassemblyloadcontext.cpp | 12 | ||||
-rw-r--r-- | src/binder/clrprivbindercoreclr.cpp | 7 | ||||
-rw-r--r-- | src/binder/inc/assemblybinder.hpp | 6 | ||||
-rw-r--r-- | src/binder/inc/clrprivbindercoreclr.h | 3 | ||||
-rw-r--r-- | src/mscorlib/src/mscorlib.txt | 5 | ||||
-rw-r--r-- | src/vm/assemblyname.cpp | 2 |
8 files changed, 41 insertions, 13 deletions
diff --git a/src/binder/assemblybinder.cpp b/src/binder/assemblybinder.cpp index 1fea74ef64..46f393b95e 100644 --- a/src/binder/assemblybinder.cpp +++ b/src/binder/assemblybinder.cpp @@ -563,6 +563,7 @@ namespace BINDER_SPACE /* in */ PEAssembly *pParentAssembly, /* in */ BOOL fNgenExplicitBind, /* in */ BOOL fExplicitBindToNativeImage, + /* in */ bool excludeAppPaths, /* out */ Assembly **ppAssembly) { HRESULT hr = S_OK; @@ -591,6 +592,7 @@ namespace BINDER_SPACE hr = BindByName(pApplicationContext, pAssemblyName, BIND_CACHE_FAILURES, + excludeAppPaths, &bindResult); IF_FAIL_GO(hr); } @@ -619,6 +621,7 @@ namespace BINDER_SPACE assemblyPath, fDoNgenExplicitBind, fExplicitBindToNativeImage, + excludeAppPaths, &bindResult)); } @@ -850,6 +853,7 @@ namespace BINDER_SPACE ((hr = BindByName(pApplicationContext, pAssemblyName, BIND_CACHE_FAILURES | BIND_CACHE_RERUN_BIND, + false, // excludeAppPaths &bindResult)) == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) ) { @@ -911,6 +915,7 @@ namespace BINDER_SPACE HRESULT AssemblyBinder::BindByName(ApplicationContext *pApplicationContext, AssemblyName *pAssemblyName, DWORD dwBindFlags, + bool excludeAppPaths, BindResult *pBindResult) { HRESULT hr = S_OK; @@ -953,6 +958,7 @@ namespace BINDER_SPACE IF_FAIL_GO(BindLocked(pApplicationContext, pRetargetedAssemblyName, dwBindFlags, + excludeAppPaths, pBindResult)); if (!pBindResult->HaveResult()) @@ -993,6 +999,7 @@ namespace BINDER_SPACE PathString &assemblyPath, BOOL fNgenExplicitBind, BOOL fExplicitBindToNativeImage, + bool excludeAppPaths, BindResult *pBindResult) { HRESULT hr = S_OK; @@ -1036,6 +1043,7 @@ namespace BINDER_SPACE { IF_FAIL_GO(BindLockedOrService(pApplicationContext, pRetargetedAssemblyName, + excludeAppPaths, &lockedBindResult)); if (lockedBindResult.HaveResult()) { @@ -1081,6 +1089,7 @@ namespace BINDER_SPACE HRESULT AssemblyBinder::BindLocked(ApplicationContext *pApplicationContext, AssemblyName *pAssemblyName, DWORD dwBindFlags, + bool excludeAppPaths, BindResult *pBindResult) { HRESULT hr = S_OK; @@ -1119,6 +1128,7 @@ namespace BINDER_SPACE IF_FAIL_GO(BindByTpaList(pApplicationContext, pAssemblyName, FALSE /*fInspectionOnly*/, + excludeAppPaths, pBindResult)); if (pBindResult->HaveResult()) { @@ -1137,6 +1147,7 @@ namespace BINDER_SPACE /* static */ HRESULT AssemblyBinder::BindLockedOrService(ApplicationContext *pApplicationContext, AssemblyName *pAssemblyName, + bool excludeAppPaths, BindResult *pBindResult) { HRESULT hr = S_OK; @@ -1147,6 +1158,7 @@ namespace BINDER_SPACE IF_FAIL_GO(BindLocked(pApplicationContext, pAssemblyName, 0 /* Do not IgnoreDynamicBinds */, + excludeAppPaths, &lockedBindResult)); if (lockedBindResult.HaveResult()) @@ -1327,6 +1339,7 @@ namespace BINDER_SPACE HRESULT AssemblyBinder::BindByTpaList(ApplicationContext *pApplicationContext, AssemblyName *pRequestedAssemblyName, BOOL fInspectionOnly, + bool excludeAppPaths, BindResult *pBindResult) { HRESULT hr = S_OK; @@ -1421,11 +1434,11 @@ namespace BINDER_SPACE // We either didn't find a candidate, or the ref-def failed. Either way; fall back to app path probing. } - bool fUseAppPathsBasedResolver = true; + bool fUseAppPathsBasedResolver = !excludeAppPaths; #if defined(FEATURE_HOST_ASSEMBLY_RESOLVER) && !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) && !defined(MDILNIGEN) // If Host Assembly Resolver is specified, then we will use that as the override for the default resolution mechanism (that uses AppPath probing). - if (!RuntimeCanUseAppPathAssemblyResolver(pApplicationContext->GetAppDomainId())) + if (fUseAppPathsBasedResolver && !RuntimeCanUseAppPathAssemblyResolver(pApplicationContext->GetAppDomainId())) { fUseAppPathsBasedResolver = false; } @@ -1899,6 +1912,7 @@ Retry: hr = BindByName(pApplicationContext, pAssemblyName, BIND_CACHE_FAILURES|BIND_CACHE_RERUN_BIND|BIND_IGNORE_REFDEF_MATCH, + false, // excludeAppPaths &bindResult); if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) diff --git a/src/binder/binderinterface.cpp b/src/binder/binderinterface.cpp index a5799e9009..6135eee97c 100644 --- a/src/binder/binderinterface.cpp +++ b/src/binder/binderinterface.cpp @@ -110,6 +110,7 @@ namespace BinderInterface pParentAssembly, fNgenExplicitBind, fExplicitBindToNativeImage, + false, // excludeAppPaths ppAssembly)); } diff --git a/src/binder/clrprivbinderassemblyloadcontext.cpp b/src/binder/clrprivbinderassemblyloadcontext.cpp index 0ea1ea3c6c..f2ed7e1f6d 100644 --- a/src/binder/clrprivbinderassemblyloadcontext.cpp +++ b/src/binder/clrprivbinderassemblyloadcontext.cpp @@ -34,6 +34,7 @@ HRESULT CLRPrivBinderAssemblyLoadContext::BindAssemblyByNameWorker(BINDER_SPACE: NULL, FALSE, //fNgenExplicitBind, FALSE, //fExplicitBindToNativeImage, + false, //excludeAppPaths, ppCoreCLRFoundAssembly); if (!FAILED(hr)) { @@ -53,10 +54,6 @@ HRESULT CLRPrivBinderAssemblyLoadContext::BindAssemblyByName(IAssemblyName * // DevDiv #933506: Exceptions thrown during AssemblyLoadContext.Load should propagate // EX_TRY { - // Check if the assembly is in the TPA list or not. - // - // HAR_TODO: For Bing scenarios, we should be able to tell the TPA Binder - // to not consult the AppPaths/App_ni_Paths. _ASSERTE(m_pTPABinder != NULL); ReleaseHolder<BINDER_SPACE::Assembly> pCoreCLRFoundAssembly; @@ -65,7 +62,9 @@ HRESULT CLRPrivBinderAssemblyLoadContext::BindAssemblyByName(IAssemblyName * SAFE_NEW(pAssemblyName, AssemblyName); IF_FAIL_GO(pAssemblyName->Init(pIAssemblyName)); - hr = m_pTPABinder->BindAssemblyByNameWorker(pAssemblyName, &pCoreCLRFoundAssembly); + // Check if the assembly is in the TPA list or not. Don't search app paths when using the TPA binder because the actual + // binder is using a host assembly resolver. + hr = m_pTPABinder->BindAssemblyByNameWorker(pAssemblyName, &pCoreCLRFoundAssembly, true /* excludeAppPaths */); if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) { // If we could not find the assembly in the TPA list, @@ -160,7 +159,8 @@ HRESULT CLRPrivBinderAssemblyLoadContext::BindUsingPEImage( /* in */ PEImage *pP { // The simple name of the assembly being requested to be bound was found in the TPA list. // Now, perform the actual bind to see if the assembly was really in the TPA assembly or not. - hr = m_pTPABinder->BindAssemblyByNameWorker(pAssemblyName, &pCoreCLRFoundAssembly); + // Don't search app paths when using the TPA binder because the actual binder is using a host assembly resolver. + hr = m_pTPABinder->BindAssemblyByNameWorker(pAssemblyName, &pCoreCLRFoundAssembly, true /* excludeAppPaths */); if (SUCCEEDED(hr)) { if (pCoreCLRFoundAssembly->GetIsInGAC()) diff --git a/src/binder/clrprivbindercoreclr.cpp b/src/binder/clrprivbindercoreclr.cpp index b791c9baca..570fc43392 100644 --- a/src/binder/clrprivbindercoreclr.cpp +++ b/src/binder/clrprivbindercoreclr.cpp @@ -15,7 +15,8 @@ using namespace BINDER_SPACE; //----------------------------------------------------------------------------- HRESULT CLRPrivBinderCoreCLR::BindAssemblyByNameWorker(BINDER_SPACE::AssemblyName *pAssemblyName, - BINDER_SPACE::Assembly **ppCoreCLRFoundAssembly) + BINDER_SPACE::Assembly **ppCoreCLRFoundAssembly, + bool excludeAppPaths) { VALIDATE_ARG_RET(pAssemblyName != nullptr && ppCoreCLRFoundAssembly != nullptr); HRESULT hr = S_OK; @@ -31,6 +32,7 @@ HRESULT CLRPrivBinderCoreCLR::BindAssemblyByNameWorker(BINDER_SPACE::AssemblyNam NULL, FALSE, //fNgenExplicitBind, FALSE, //fExplicitBindToNativeImage, + excludeAppPaths, ppCoreCLRFoundAssembly); if (!FAILED(hr)) { @@ -59,7 +61,7 @@ HRESULT CLRPrivBinderCoreCLR::BindAssemblyByName(IAssemblyName *pIAssemblyNa SAFE_NEW(pAssemblyName, AssemblyName); IF_FAIL_GO(pAssemblyName->Init(pIAssemblyName)); - hr = BindAssemblyByNameWorker(pAssemblyName, &pCoreCLRFoundAssembly); + hr = BindAssemblyByNameWorker(pAssemblyName, &pCoreCLRFoundAssembly, false /* excludeAppPaths */); IF_FAIL_GO(hr); *ppAssembly = pCoreCLRFoundAssembly.Extract(); @@ -167,6 +169,7 @@ HRESULT CLRPrivBinderCoreCLR::Bind(SString &assemblyDisplayName, pParentAssembly, fNgenExplicitBind, fExplicitBindToNativeImage, + false, // excludeAppPaths &pAsm); if(SUCCEEDED(hr)) { diff --git a/src/binder/inc/assemblybinder.hpp b/src/binder/inc/assemblybinder.hpp index 81d42964ca..4ca0c4f18c 100644 --- a/src/binder/inc/assemblybinder.hpp +++ b/src/binder/inc/assemblybinder.hpp @@ -47,6 +47,7 @@ namespace BINDER_SPACE /* in */ PEAssembly *pParentAssembly, /* in */ BOOL fNgenExplicitBind, /* in */ BOOL fExplicitBindToNativeImage, + /* in */ bool excludeAppPaths, /* out */ Assembly **ppAssembly); static HRESULT BindToSystem(/* in */ SString &systemDirectory, @@ -128,6 +129,7 @@ namespace BINDER_SPACE static HRESULT BindByName(/* in */ ApplicationContext *pApplicationContext, /* in */ AssemblyName *pAssemblyName, /* in */ DWORD dwBindFlags, + /* in */ bool excludeAppPaths, /* out */ BindResult *pBindResult); // See code:BINDER_SPACE::AssemblyBinder::GetAssembly for info on fNgenExplicitBind @@ -137,14 +139,17 @@ namespace BINDER_SPACE /* in */ PathString &assemblyPath, /* in */ BOOL fNgenExplicitBind, /* in */ BOOL fExplicitBindToNativeImage, + /* in */ bool excludeAppPaths, /* out */ BindResult *pBindResult); static HRESULT BindLocked(/* in */ ApplicationContext *pApplicationContext, /* in */ AssemblyName *pAssemblyName, /* in */ DWORD dwBindFlags, + /* in */ bool excludeAppPaths, /* out */ BindResult *pBindResult); static HRESULT BindLockedOrService(/* in */ ApplicationContext *pApplicationContext, /* in */ AssemblyName *pAssemblyName, + /* in */ bool excludeAppPaths, /* out */ BindResult *pBindResult); static HRESULT FindInExecutionContext(/* in */ ApplicationContext *pApplicationContext, @@ -154,6 +159,7 @@ namespace BINDER_SPACE static HRESULT BindByTpaList(/* in */ ApplicationContext *pApplicationContext, /* in */ AssemblyName *pRequestedAssemblyName, /* in */ BOOL fInspectionOnly, + /* in */ bool excludeAppPaths, /* out */ BindResult *pBindResult); static HRESULT Register(/* in */ ApplicationContext *pApplicationContext, diff --git a/src/binder/inc/clrprivbindercoreclr.h b/src/binder/inc/clrprivbindercoreclr.h index 2aa1283448..38e43f706c 100644 --- a/src/binder/inc/clrprivbindercoreclr.h +++ b/src/binder/inc/clrprivbindercoreclr.h @@ -70,7 +70,8 @@ public: HRESULT BindAssemblyByNameWorker( BINDER_SPACE::AssemblyName *pAssemblyName, - BINDER_SPACE::Assembly **ppCoreCLRFoundAssembly); + BINDER_SPACE::Assembly **ppCoreCLRFoundAssembly, + bool excludeAppPaths); //========================================================================= // Internal implementation details diff --git a/src/mscorlib/src/mscorlib.txt b/src/mscorlib/src/mscorlib.txt index e393c11115..de472423eb 100644 --- a/src/mscorlib/src/mscorlib.txt +++ b/src/mscorlib/src/mscorlib.txt @@ -1470,8 +1470,9 @@ NotSupported_NoTypeInfo = Cannot resolve {0} to a TypeInfo object. NotSupported_PIAInAppxProcess = A Primary Interop Assembly is not supported in AppX. #endif #if FEATURE_WINDOWSPHONE -NotSupported_WindowsPhone = {0} is not supported on Windows Phone. -NotSupported_AssemblyLoadCodeBase = Assembly.Load with a Codebase is not supported on Windows Phone. +; Not referring to "Windows Phone" in the messages, as FEATURE_WINDOWSPHONE is defined for .NET Core as well. +NotSupported_WindowsPhone = {0} is not supported. +NotSupported_AssemblyLoadCodeBase = Assembly.Load with a Codebase is not supported. #endif ; TypeLoadException diff --git a/src/vm/assemblyname.cpp b/src/vm/assemblyname.cpp index 3a66851e34..173f3dbbdd 100644 --- a/src/vm/assemblyname.cpp +++ b/src/vm/assemblyname.cpp @@ -85,7 +85,9 @@ FCIMPL1(Object*, AssemblyNameNative::GetFileInformation, StringObject* filenameU AssemblySpec spec; spec.InitializeSpec(TokenFromRid(mdtAssembly,1),pImage->GetMDImport(),NULL,TRUE); +#ifndef FEATURE_CORECLR spec.SetCodeBase(sUrl); +#endif spec.AssemblyNameInit(&gc.result, pImage); HELPER_METHOD_FRAME_END(); |