From f8be5938f7b238902bfdbcdfa648436921331f97 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Mon, 5 Mar 2018 10:05:32 +0000 Subject: [PATCH 1/2] [Java.Interop.Tools.Cecil] Change DirectoryAssemblyResolver to allow forced loading. Context https://github.com/xamarin/xamarin-android/issues/1154 One of the problems we currently face is that our build system resolves `ref` netstandard libraries. With the current cache system, onces an assembly has been loaded into the Cecil cache it only ever uses that assembly. We might need to replace the current cached version with a new one if we detect a `ref` and need to reload the `lib`. --- .../Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs b/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs index 7b6b2d484..31c677706 100644 --- a/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs +++ b/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs @@ -110,14 +110,14 @@ public Dictionary ToResolverCache () return new Dictionary(cache); } - public virtual AssemblyDefinition Load (string fileName) + public virtual AssemblyDefinition Load (string fileName, bool forceLoad = false) { if (!File.Exists (fileName)) return null; AssemblyDefinition assembly; var name = Path.GetFileNameWithoutExtension (fileName); - if (cache.TryGetValue (name, out assembly)) + if (!forceLoad && cache.TryGetValue (name, out assembly)) return assembly; try { @@ -125,7 +125,7 @@ public virtual AssemblyDefinition Load (string fileName) } catch (Exception e) { Diagnostic.Error (9, e, "Error while loading assembly: {0}", fileName); } - cache.Add (name, assembly); + cache [name] = assembly; return assembly; } From a9ec2da976ad3fbe287854160a4f737216ac5fee Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Mon, 5 Mar 2018 10:23:21 +0000 Subject: [PATCH 2/2] ff --- .../Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs b/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs index 31c677706..c596fed86 100644 --- a/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs +++ b/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs @@ -115,7 +115,7 @@ public virtual AssemblyDefinition Load (string fileName, bool forceLoad = false) if (!File.Exists (fileName)) return null; - AssemblyDefinition assembly; + AssemblyDefinition assembly = null; var name = Path.GetFileNameWithoutExtension (fileName); if (!forceLoad && cache.TryGetValue (name, out assembly)) return assembly;