fix Mirror.dll Resolve() issues in ReaderWriterProcessor when resolving from the passed Mirror.dll.

DefaultAssemblyResolver doesn't work with ILPostProcessor.
This commit is contained in:
vis2k 2021-08-23 17:16:08 +08:00
parent d44b98395d
commit 489e55e0b7

View File

@ -91,22 +91,25 @@ public override ILPostProcessResult Process(ICompiledAssembly compiledAssembly)
if (mirrorAssemblyPath != null)
{
Log.Warning("Mirror Ref: " + mirrorAssemblyPath);
// resolve mirror assembly
// TODO is this safe with ILPP multithreading though?
// (it sure has to exist while we process this assembly since it's referenced)
// TODO use our custom resolver. default fails to resolve in ReaderWriterProcessor.LoadMessageReadWriter -> IsInterface extension
using (DefaultAssemblyResolver mirrorAsmResolver = new DefaultAssemblyResolver())
using (AssemblyDefinition mirrorAssembly = AssemblyDefinition.ReadAssembly(mirrorAssemblyPath, new ReaderParameters { ReadWrite = false, ReadSymbols = false, AssemblyResolver = mirrorAsmResolver }))
// DefaultAssemblyResolver does not work with ILPostProcessor.
// we need to use our custom resolver again.
// we already have it, so simply call .Resolve().
// (need to pass correct reader parameters again to
// avoid System.Private.CoreLib resolve issues again)
// otherwise we get exceptions in ReaderWriterProcessor.
AssemblyNameReference mirrorNameReference = AssemblyNameReference.Parse(mirrorAssemblyPath);
AssemblyDefinition mirrorAssembly = asmResolver.Resolve(mirrorNameReference, readerParameters);
// weave this assembly. and pass mirror.dll.
if (weaver.Weave(asmDef, mirrorAssembly))
{
// weave this assembly. and pass mirror.dll.
if (weaver.Weave(asmDef, mirrorAssembly))
{
Log.Warning($"Weaving succeeded for: {compiledAssembly.Name}");
// TODO return modified assembly
// TODO AND pdb / debug symbols
}
else Log.Error($"Weaving failed for: {compiledAssembly.Name}");
Log.Warning($"Weaving succeeded for: {compiledAssembly.Name}");
// TODO return modified assembly
// TODO AND pdb / debug symbols
}
else Log.Error($"Weaving failed for: {compiledAssembly.Name}");
}
// we ARE Mirror.dll
else