Hi friends
I could discover that we can redirect to a specific version of a .net assembly by using configuration file as below:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="myAssembly"
publicKeyToken="32ab4ba45e0a69a1"
culture="en-us" />
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
But I do not want to use that config file. In fact I can not do that. I am working on a C++ application which also have some .net modules. We explicitly load the CLR by using stuff as shown below:
ICLRMetaHost *m_pMetaHost = NULL;
HRESULT hr = CLRCreateInstance(CLSID_CLRMetaHost, IID_ICLRMetaHost, (LPVOID*)&m_pMetaHost);
...
hr = m_pMetaHost->GetRuntime(L"v4.0.30319", IID_ICLRRuntimeInfo, (LPVOID *)&m_pRuntimeInfo);
if (!m_pRuntimeInfo) {
*pHR = hr;
return false;
}
...
hr = m_pClrHost->SetHostControl(static_cast<IHostControl *>(this));
if (FAILED(hr)) {
*pHR = hr;
return false;
}
ICLRControl *pCLRControl = NULL;
hr = m_pClrHost->GetCLRControl(&pCLRControl);
if (FAILED(hr) || pCLRControl == NULL) {
*pHR = hr;
return false;
}
...
#define ADM_ASSEMBLY_REF L"MyAssembly, Version=%s, Culture=neutral, PublicKeyToken=1c8d91d2de78b25e"
#define ADM_CLASS_REF L"My.Namespace.MyAppDomainManager"
wchar_t versionInfo[256];
MultiByteToWideChar(CP_ACP, 0, MI_VERSION_STRING, -1, versionInfo, sizeof(versionInfo) / sizeof(wchar_t));
wchar_t assemblyRef[512];
swprintf(assemblyRef, sizeof(assemblyRef), ADM_ASSEMBLY_REF, versionInfo);
hr = pCLRControl->SetAppDomainManagerType(assemblyRef, ADM_CLASS_REF);
Can someone please tell how can I specify which version of a specific assembly is to be redirected to? Please note that I want to do this with respect to default application only. I am not creating any new application domain. I think while initializing/loading the CLR, we might have some way to specify the configuration information via code instead of using any physical configuration file.
Any help/direction is heartily appreciated.
Thanks in advance
Aseem Sharma