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.
4 // ============================================================
11 // Implements the public AssemblyBinder interface
13 // ============================================================
15 #include "assemblybinder.hpp"
16 #include "assemblyname.hpp"
17 #include "applicationcontext.hpp"
18 #include "binderinterface.hpp"
19 #include "bindresult.inl"
24 using namespace BINDER_SPACE;
26 namespace BinderInterface
35 hr = AssemblyBinder::Startup();
42 HRESULT SetupContext(LPCWSTR wszApplicationBase,
44 IUnknown **ppIApplicationContext)
51 BINDER_LOG_ENTER(L"BinderInterface::SetupContext");
53 // Verify input arguments
54 IF_FALSE_GO(ppIApplicationContext != NULL);
57 ReleaseHolder<ApplicationContext> pApplicationContext;
59 SAFE_NEW(pApplicationContext, ApplicationContext);
60 IF_FAIL_GO(pApplicationContext->Init());
61 pApplicationContext->SetAppDomainId(dwAppDomainId);
62 *ppIApplicationContext = static_cast<IUnknown *>(pApplicationContext.Extract());
66 BINDER_LOG_LEAVE_HR(L"BinderInterface::SetupContext", hr);
73 // See code:BINDER_SPACE::AssemblyBinder::GetAssembly for info on fNgenExplicitBind
74 // and fExplicitBindToNativeImage, and see code:CEECompileInfo::LoadAssemblyByPath
75 // for an example of how they're used.
76 HRESULT Bind(IUnknown *pIApplicationContext,
77 SString &assemblyDisplayName,
79 PEAssembly *pParentAssembly,
80 BOOL fNgenExplicitBind,
81 BOOL fExplicitBindToNativeImage,
82 BINDER_SPACE::Assembly **ppAssembly)
89 BINDER_LOG_ENTER(L"BinderInterface::Bind");
91 // Verify input arguments
92 IF_FALSE_GO(pIApplicationContext != NULL);
93 IF_FALSE_GO(ppAssembly != NULL);
96 ApplicationContext *pApplicationContext =
97 static_cast<ApplicationContext *>(pIApplicationContext);
99 ReleaseHolder<AssemblyName> pAssemblyName;
100 if (!assemblyDisplayName.IsEmpty())
102 SAFE_NEW(pAssemblyName, AssemblyName);
103 IF_FAIL_GO(pAssemblyName->Init(assemblyDisplayName));
106 IF_FAIL_GO(AssemblyBinder::BindAssembly(pApplicationContext,
111 fExplicitBindToNativeImage,
112 false, // excludeAppPaths
117 BINDER_LOG_LEAVE_HR(L"BinderInterface::Bind", hr);
119 EX_CATCH_HRESULT(hr);
124 HRESULT BindToSystem(SString &sSystemDirectory,
125 BINDER_SPACE::Assembly **ppSystemAssembly,
126 bool fBindToNativeImage)
130 IF_FALSE_GO(ppSystemAssembly != NULL);
136 IF_FAIL_GO(AssemblyBinder::BindToSystem(sSystemDirectory, ppSystemAssembly, fBindToNativeImage));
138 EX_CATCH_HRESULT(hr);
144 HRESULT SetupBindingPaths(IUnknown *pIApplicationContext,
145 SString &sTrustedPlatformAssemblies,
146 SString &sPlatformResourceRoots,
148 SString &sAppNiPaths)
155 BINDER_LOG_ENTER(L"BinderInterface::SetupBindingPaths");
157 // Verify input arguments
158 IF_FALSE_GO(pIApplicationContext != NULL);
161 ApplicationContext *pApplicationContext =
162 static_cast<ApplicationContext *>(pIApplicationContext);
163 _ASSERTE(pApplicationContext != NULL);
165 IF_FAIL_GO(pApplicationContext->SetupBindingPaths(sTrustedPlatformAssemblies, sPlatformResourceRoots, sAppPaths, sAppNiPaths, TRUE /* fAcquireLock */));
169 BINDER_LOG_LEAVE_HR(L"BinderInterface::SetupBindingPaths", hr);
171 EX_CATCH_HRESULT(hr);
176 #ifdef BINDER_DEBUG_LOG
177 HRESULT Log(LPCWSTR wszMessage)
184 BINDER_LOG((WCHAR *) wszMessage);
186 EX_CATCH_HRESULT(hr);
190 #endif // BINDER_DEBUG_LOG