#using <mscorlib.dll>
#using <System.dll>
#using <System.Xml.dll>
ref class AssemblyResolveProxy
{
public:
AssemblyResolveProxy() {
System::AppDomain^ currentDomain = System::AppDomain::CurrentDomain;
currentDomain->AssemblyResolve += gcnew System::ResolveEventHandler(this, &AssemblyResolveProxy::currentDomain_AssemblyResolve);
}
private:
System::Reflection::Assembly^ currentDomain_AssemblyResolve(System::Object^ sender, System::ResolveEventArgs^ args)
{
System::String^ myPath = System::Reflection::Assembly::GetExecutingAssembly()->Location;
System::String^ myDir = System::IO::Path::GetDirectoryName(myPath);
System::String split[] = nullptr;
//System::String^ symbol = ",";
//System::Char cSymbol[] = symbol->ToCharArray();
//System::String split[] = args->Name->Split(cSymbol); // TODO: is there a better way? AssemblyName.Parse() doesn't exist
//System::String^ simpleAssemblyName = split[0];
System::String^ pAssemplyInfo = args->Name;
cli::array<System::String^> ^tempItems = pAssemplyInfo->Split(',');
System::String^ pAssemplyName = tempItems[0];
System::String^ resolveAssemblyPath = System::IO::Path::Combine(myDir, (gcnew System::Text::StringBuilder(pAssemplyName))->Append(/*MSG0*/".dll")->ToString());
if (System::IO::File::Exists(resolveAssemblyPath))
return System::Reflection::Assembly::LoadFrom(resolveAssemblyPath);
return nullptr;
}
};
class AssemblyResolver
{
gcroot<AssemblyResolveProxy^> m_AssemblyResolve;
public:
AssemblyResolver()
{
m_AssemblyResolve = gcnew AssemblyResolveProxy();
}
};
static AssemblyResolver m_assemblyResolver;