1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
7 #include "assemblybinder.hpp"
8 #include "coreclrbindercommon.h"
9 #include "clrprivbindercoreclr.h"
10 #include "clrprivbinderutil.h"
12 using namespace BINDER_SPACE;
14 //=============================================================================
16 //-----------------------------------------------------------------------------
18 HRESULT CCoreCLRBinderHelper::Init()
24 hr = AssemblyBinder::Startup();
31 HRESULT CCoreCLRBinderHelper::DefaultBinderSetupContext(DWORD dwAppDomainId,CLRPrivBinderCoreCLR **ppTPABinder)
36 if(ppTPABinder != NULL)
38 ReleaseHolder<CLRPrivBinderCoreCLR> pBinder;
39 SAFE_NEW(pBinder, CLRPrivBinderCoreCLR);
41 BINDER_SPACE::ApplicationContext *pApplicationContext = pBinder->GetAppContext();
42 hr = pApplicationContext->Init();
45 pApplicationContext->SetAppDomainId(dwAppDomainId);
46 pBinder->SetManagedAssemblyLoadContext(NULL);
47 *ppTPABinder = clr::SafeAddRef(pBinder.Extract());
57 HRESULT CCoreCLRBinderHelper::GetAssemblyIdentity(LPCSTR szTextualIdentity,
58 BINDER_SPACE::ApplicationContext *pApplicationContext,
59 NewHolder<AssemblyIdentityUTF8> &assemblyIdentityHolder)
62 VALIDATE_ARG_RET(szTextualIdentity != NULL);
66 AssemblyIdentityUTF8 *pAssemblyIdentity = NULL;
67 if (pApplicationContext != NULL)
69 // This returns a cached copy owned by application context
70 hr = pApplicationContext->GetAssemblyIdentity(szTextualIdentity, &pAssemblyIdentity);
73 assemblyIdentityHolder = pAssemblyIdentity;
74 assemblyIdentityHolder.SuppressRelease();
79 SString sTextualIdentity;
81 sTextualIdentity.SetUTF8(szTextualIdentity);
83 // This is a private copy
84 pAssemblyIdentity = new AssemblyIdentityUTF8();
85 hr = TextualIdentityParser::Parse(sTextualIdentity, pAssemblyIdentity);
88 pAssemblyIdentity->PopulateUTF8Fields();
89 assemblyIdentityHolder = pAssemblyIdentity;
98 //=============================================================================
99 // Functions that provides binding services beyond the ICLRPrivInterface
100 //-----------------------------------------------------------------------------
102 HRESULT CCoreCLRBinderHelper::BindToSystem(ICLRPrivAssembly **ppSystemAssembly, bool fBindToNativeImage)
105 VALIDATE_ARG_RET(ppSystemAssembly != NULL);
109 ReleaseHolder<BINDER_SPACE::Assembly> pAsm;
110 StackSString systemPath(SystemDomain::System()->SystemDirectory());
111 hr = AssemblyBinder::BindToSystem(systemPath, &pAsm, fBindToNativeImage);
114 _ASSERTE(pAsm != NULL);
115 *ppSystemAssembly = pAsm.Extract();
118 EX_CATCH_HRESULT(hr);
123 HRESULT CCoreCLRBinderHelper::BindToSystemSatellite(SString &systemPath,
124 SString &sSimpleName,
125 SString &sCultureName,
126 ICLRPrivAssembly **ppSystemAssembly)
129 VALIDATE_ARG_RET(ppSystemAssembly != NULL && !systemPath.IsEmpty());
133 ReleaseHolder<BINDER_SPACE::Assembly> pAsm;
134 hr = AssemblyBinder::BindToSystemSatellite(systemPath, sSimpleName, sCultureName, &pAsm);
137 _ASSERTE(pAsm != NULL);
138 *ppSystemAssembly = pAsm.Extract();
141 EX_CATCH_HRESULT(hr);
146 HRESULT CCoreCLRBinderHelper::GetAssemblyFromImage(PEImage *pPEImage,
147 PEImage *pNativePEImage,
148 ICLRPrivAssembly **ppAssembly)
151 VALIDATE_ARG_RET(pPEImage != NULL && ppAssembly != NULL);
155 ReleaseHolder<BINDER_SPACE::Assembly> pAsm;
156 hr = AssemblyBinder::GetAssemblyFromImage(pPEImage, pNativePEImage, &pAsm);
159 _ASSERTE(pAsm != nullptr);
160 *ppAssembly = pAsm.Extract();
163 EX_CATCH_HRESULT(hr);
168 //=============================================================================
169 // Explicitly bind to an assembly by filepath
170 //=============================================================================
172 HRESULT CCoreCLRBinderHelper::GetAssembly(/* in */ SString &assemblyPath,
173 /* in */ BOOL fInspectionOnly,
174 /* in */ BOOL fIsInGAC,
175 /* in */ BOOL fExplicitBindToNativeImage,
176 /* out */ BINDER_SPACE::Assembly **ppAssembly)
178 return AssemblyBinder::GetAssembly(assemblyPath,
181 fExplicitBindToNativeImage,