From 80c7ab1e8e44cde36673271929fb94749f75f2e2 Mon Sep 17 00:00:00 2001 From: Shaun Walker Date: Tue, 14 Apr 2020 14:46:44 -0400 Subject: [PATCH] Enhancement to load debugging symbols ( *.pdb ) if they exist in the /bin folder. This enables debugging of modules. --- .../OqtaneServiceCollectionExtensions.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs b/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs index aef47901..685327a9 100644 --- a/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs +++ b/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs @@ -112,14 +112,22 @@ namespace Microsoft.Extensions.DependencyInjection var assembliesFolder = new DirectoryInfo(assemblyPath); // iterate through Oqtane assemblies in /bin ( filter is narrow to optimize loading process ) - foreach (var file in assembliesFolder.EnumerateFiles($"*.{pattern}.*.dll")) + foreach (var dll in assembliesFolder.EnumerateFiles($"*.{pattern}.*.dll")) { // check if assembly is already loaded - var assembly = Assemblies.FirstOrDefault(a =>!a.IsDynamic && a.Location == file.FullName); + var assembly = Assemblies.FirstOrDefault(a =>!a.IsDynamic && a.Location == dll.FullName); if (assembly == null) { - // load assembly from stream to prevent locking file ( as long as dependencies are in /bin they will load as well ) - assembly = AssemblyLoadContext.Default.LoadFromStream(new MemoryStream(File.ReadAllBytes(file.FullName))); + // load assembly ( and symbols ) from stream to prevent locking files ( as long as dependencies are in /bin they will load as well ) + string pdb = dll.FullName.Replace(".dll", ".pdb"); + if (File.Exists(pdb)) + { + assembly = AssemblyLoadContext.Default.LoadFromStream(new MemoryStream(File.ReadAllBytes(dll.FullName)), new MemoryStream(File.ReadAllBytes(pdb))); + } + else + { + assembly = AssemblyLoadContext.Default.LoadFromStream(new MemoryStream(File.ReadAllBytes(dll.FullName))); + } if (pattern == "Module") { // build a list of module assemblies