From 489e55e0b71e2a4215c72332c728aaf4c4d953e0 Mon Sep 17 00:00:00 2001 From: vis2k Date: Mon, 23 Aug 2021 17:16:08 +0800 Subject: [PATCH] fix Mirror.dll Resolve() issues in ReaderWriterProcessor when resolving from the passed Mirror.dll. DefaultAssemblyResolver doesn't work with ILPostProcessor. --- .../ILPostProcessorHook.cs | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/Assets/Mirror/Editor/Weaver/EntryPointILPostProcessor/ILPostProcessorHook.cs b/Assets/Mirror/Editor/Weaver/EntryPointILPostProcessor/ILPostProcessorHook.cs index e26dab0e1..96059a690 100644 --- a/Assets/Mirror/Editor/Weaver/EntryPointILPostProcessor/ILPostProcessorHook.cs +++ b/Assets/Mirror/Editor/Weaver/EntryPointILPostProcessor/ILPostProcessorHook.cs @@ -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