I'm working a VSIX project that is a command to build a DLL with reflection and my target DLL does reflection too.
I load the target DLL with
asmBase = System.IO.Path.GetDirectoryName(assemblyName);
var settings = System.Configuration.ConfigurationManager.ConnectionStrings[0];
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
asm = System.Reflection.Assembly.Load(System.IO.File.ReadAllBytes(assemblyName));
And here is my AssemblyResolve event
private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
//This handler is called only when the common language runtime tries to bind to the assembly and fails.
//Retrieve the list of referenced assemblies in an array of AssemblyName.
Assembly MyAssembly, objExecutingAssemblies;
string strTempAssmbPath = "";
objExecutingAssemblies = args.RequestingAssembly;
AssemblyName[] arrReferencedAssmbNames = objExecutingAssemblies.GetReferencedAssemblies();
//Loop through the array of referenced assembly names.
foreach (AssemblyName strAssmbName in arrReferencedAssmbNames)
{
//Check for the assembly names that have raised the "AssemblyResolve" event.
if (strAssmbName.FullName.Substring(0, strAssmbName.FullName.IndexOf(",")) == args.Name.Substring(0, args.Name.IndexOf(",")))
{
//Build the path of the assembly from where it has to be loaded.
strTempAssmbPath = asmBase + "\\" + args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll";
break;
}
}
//Load the assembly from the specified path.
MyAssembly = Assembly.LoadFrom(strTempAssmbPath);
//Return the loaded assembly.
return MyAssembly;
}
My issue is when my target DLL executes this line of code:
string cachePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
cachePath = Path.GetDirectoryName(cachePath);
The GetExecutingAssembly
method is throwing a "path is not legal form" exception for me.
What is the expected path result of the GetExecutingAssembly method?
I tried to use
System.Diagnostics.Debug.WriteLine(cachePath);
But it didn't show the message.