I'm currently playing with Mono.Cecil to add an assembly reference into an already compiled assembly.
I'm using this code to add the reference:
this.tracerReference = this.module.ImportReference(typeof(Tracer).GetMethod("Trace", new Type[]
{
typeof(String)
}));
Tracer is a class from another project. Once I'm done with my modifications to the loaded assembly, I'm saving it like this:
var newAssemblyName =
Path.GetFileNameWithoutExtension(this._assemblyPath) + ".modified" + Path.GetExtension(_assemblyPath);
var directory = Path.GetDirectoryName(_assemblyPath);
Console.WriteLine(newAssemblyName);
module.Write(Path.Join(directory, newAssemblyName));
Once I try to run the new dll, I see this:
$ dotnet instrospect.TestCli.dll
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'instrospect.types, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
File name: 'instrospect.types, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
[1] 4555 abort dotnet instrospect.TestCli.dll
Even though the dll in question, introspect.types is in the same directory as introspectTestCli.dll it does not find it. Am I missing anything?