From 76906f90f7a2041504a54ffcb8e4f2cd774a59aa Mon Sep 17 00:00:00 2001 From: filipw Date: Thu, 18 May 2017 22:23:33 +0300 Subject: [PATCH 1/2] check if folder path exists before attempting to load assemblies --- src/OmniSharp.Host/Services/AssemblyLoader.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/OmniSharp.Host/Services/AssemblyLoader.cs b/src/OmniSharp.Host/Services/AssemblyLoader.cs index 3f3ecf5d48..ff927a083f 100644 --- a/src/OmniSharp.Host/Services/AssemblyLoader.cs +++ b/src/OmniSharp.Host/Services/AssemblyLoader.cs @@ -38,6 +38,12 @@ public IReadOnlyList LoadAllFrom(string folderPath) { if (string.IsNullOrWhiteSpace(folderPath)) return Array.Empty(); + if (!Directory.Exists(folderPath)) + { + _logger.LogWarning($"Attempted to load assemblies from '{folderPath}' but that path doesn't exist."); + return Array.Empty(); + } + var assemblies = new List(); foreach (var filePath in Directory.EnumerateFiles(folderPath, "*.dll")) { From 0cbaf04051acd2581368eb346126c6f8413ea86b Mon Sep 17 00:00:00 2001 From: filipw Date: Thu, 18 May 2017 22:27:01 +0300 Subject: [PATCH 2/2] extra try/catch --- src/OmniSharp.Host/Services/AssemblyLoader.cs | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/OmniSharp.Host/Services/AssemblyLoader.cs b/src/OmniSharp.Host/Services/AssemblyLoader.cs index ff927a083f..b576cce32f 100644 --- a/src/OmniSharp.Host/Services/AssemblyLoader.cs +++ b/src/OmniSharp.Host/Services/AssemblyLoader.cs @@ -38,23 +38,26 @@ public IReadOnlyList LoadAllFrom(string folderPath) { if (string.IsNullOrWhiteSpace(folderPath)) return Array.Empty(); - if (!Directory.Exists(folderPath)) + try { - _logger.LogWarning($"Attempted to load assemblies from '{folderPath}' but that path doesn't exist."); - return Array.Empty(); - } + var assemblies = new List(); - var assemblies = new List(); - foreach (var filePath in Directory.EnumerateFiles(folderPath, "*.dll")) - { - var assembly = LoadFromPath(filePath); - if (assembly != null) + foreach (var filePath in Directory.EnumerateFiles(folderPath, "*.dll")) { - assemblies.Add(assembly); + var assembly = LoadFromPath(filePath); + if (assembly != null) + { + assemblies.Add(assembly); + } } - } - return assemblies; + return assemblies; + } + catch (Exception ex) + { + _logger.LogError(ex, $"An error occurred when attempting to access '{folderPath}'."); + return Array.Empty(); + } } private Assembly LoadFromPath(string assemblyPath)