diff --git a/src/double/Edge.js/dotnetcore/coreclrembedding.cs b/src/double/Edge.js/dotnetcore/coreclrembedding.cs index 7a1e8a86..d464ae7d 100644 --- a/src/double/Edge.js/dotnetcore/coreclrembedding.cs +++ b/src/double/Edge.js/dotnetcore/coreclrembedding.cs @@ -11,9 +11,7 @@ using System.Collections; using System.Threading.Tasks; using System.IO; -using System.Diagnostics; using Microsoft.Extensions.DependencyModel; -using Semver; [StructLayout(LayoutKind.Sequential)] // ReSharper disable once CheckNamespace @@ -172,16 +170,16 @@ protected override Assembly Load(AssemblyName assemblyName) } } } - + DebugMessage("EdgeAssemblyLoadContext::Load (CLR) - Assembly {0} was not found in EdgeAssemblyResolver", assemblyName.Name); return null; } } private class EdgeAssemblyResolver { - internal readonly Dictionary CompileAssemblies = new Dictionary(StringComparer.OrdinalIgnoreCase); - private readonly Dictionary _libraries = new Dictionary(StringComparer.OrdinalIgnoreCase); - private readonly Dictionary _nativeLibraries = new Dictionary(StringComparer.OrdinalIgnoreCase); + internal readonly Dictionary CompileAssemblies = new(StringComparer.OrdinalIgnoreCase); + private readonly Dictionary _libraries = new(StringComparer.OrdinalIgnoreCase); + private readonly Dictionary _nativeLibraries = new(StringComparer.OrdinalIgnoreCase); private readonly IList _knownPaths = new List(); private readonly string _packagesPath; @@ -201,8 +199,11 @@ public EdgeAssemblyResolver() { profileDirectory = Environment.GetEnvironmentVariable("HOME"); } - - _packagesPath = Path.Combine(profileDirectory, ".nuget", "packages"); + + if (!String.IsNullOrEmpty(profileDirectory)) + { + _packagesPath = Path.Combine(profileDirectory, ".nuget", "packages"); + } } DebugMessage("EdgeAssemblyResolver::ctor (CLR) - Packages path is {0}", _packagesPath); @@ -249,8 +250,11 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon foreach (RuntimeLibrary runtimeLibrary in dependencyContext.RuntimeLibraries) { + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing runtime dependency {1} {0}", runtimeLibrary.Name, runtimeLibrary.Type); + if (!_libraries.ContainsKey(runtimeLibrary.Name) && CompileAssemblies.ContainsKey(runtimeLibrary.Name)) { + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added runtime assembly {1} from {0}", CompileAssemblies[runtimeLibrary.Name], runtimeLibrary.Name); _libraries[runtimeLibrary.Name] = CompileAssemblies[runtimeLibrary.Name]; } @@ -261,7 +265,6 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon continue; } - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing runtime dependency {1} {0}", runtimeLibrary.Name, runtimeLibrary.Type); List assets = runtimeLibrary.RuntimeAssemblyGroups.GetRuntimeAssets(RuntimeInformation.RuntimeIdentifier).ToList(); @@ -582,12 +585,14 @@ private bool TryAddAssembly(string assemblyName) private static readonly bool DebugMode = Environment.GetEnvironmentVariable("EDGE_DEBUG") == "1"; private static readonly long MinDateTimeTicks = 621355968000000000; - private static readonly ConcurrentDictionary>>> TypePropertyAccessors = new ConcurrentDictionary>>>(); + private static readonly ConcurrentDictionary>>> TypePropertyAccessors = new(); private static readonly int PointerSize = Marshal.SizeOf(); private static readonly int V8BufferDataSize = Marshal.SizeOf(); private static readonly int V8ObjectDataSize = Marshal.SizeOf(); private static readonly int V8ArrayDataSize = Marshal.SizeOf(); - private static readonly ConcurrentDictionary> Compilers = new ConcurrentDictionary>(); + private static readonly ConcurrentDictionary> Compilers = new(); + private static readonly IList _failedAssemblyResolver = new List(); + public static void Initialize(IntPtr context, IntPtr exception) { @@ -597,7 +602,7 @@ public static void Initialize(IntPtr context, IntPtr exception) // The call to Marshal.PtrToStructure should be working // This appears to be a .Net Core issue - https://github.com/dotnet/coreclr/issues/22394 - // Manually marshaling as a work around + // Manually marshaling as a workaround //EdgeBootstrapperContext bootstrapperContext = Marshal.PtrToStructure(context); EdgeBootstrapperContext bootstrapperContext = new EdgeBootstrapperContext { @@ -630,7 +635,7 @@ public static void Initialize(IntPtr context, IntPtr exception) private static Assembly Assembly_Resolving(AssemblyLoadContext arg1, AssemblyName arg2) { - if (arg2.Name == "System.Core") + if (arg2.Name == "System.Core" || _failedAssemblyResolver.Contains(arg2.Name)) { return null; } @@ -641,7 +646,7 @@ private static Assembly Assembly_Resolving(AssemblyLoadContext arg1, AssemblyNam { return LoadContext.LoadFromAssemblyName(arg2); } - + _failedAssemblyResolver.Add(arg2.Name); DebugMessage("CoreCLREmbedding::Assembly_Resolving (CLR) - Unable to resolve the assembly using the manifest list, returning null"); return null;