From 9b906dc8536316f78f602e3ceb47a3c519178d28 Mon Sep 17 00:00:00 2001 From: oguzhankoral Date: Sun, 1 Dec 2024 02:55:12 +0300 Subject: [PATCH] load assemblies manually --- .../GitHubPullRequestAnalyzer.cs | 43 ++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/Sdk/FeatureImpactAnalyzer/GitHubPullRequestAnalyzer.cs b/Sdk/FeatureImpactAnalyzer/GitHubPullRequestAnalyzer.cs index 289372812..4d5dee9a6 100644 --- a/Sdk/FeatureImpactAnalyzer/GitHubPullRequestAnalyzer.cs +++ b/Sdk/FeatureImpactAnalyzer/GitHubPullRequestAnalyzer.cs @@ -133,15 +133,48 @@ private List GetFeatureImpactAttributes(string methodName) { var impactedFeatures = new List(); - // Load all assemblies in the current AppDomain - var assemblies = AppDomain - .CurrentDomain.GetAssemblies() - .Where(a => a.FullName != null && a.FullName.StartsWith("Speckle")) - .ToList(); + var assemblies = new List(); + // Load all assemblies in the current AppDomain string? solutionDirectory = Path.GetFullPath( Path.Combine(Assembly.GetExecutingAssembly().Location, "..", "..", "..") ); + if (!string.IsNullOrEmpty(solutionDirectory)) + { + // Search for all DLLs in the parent directory and subdirectories + var dllFiles = Directory + .GetFiles(solutionDirectory, "*.dll", SearchOption.AllDirectories) + .Where(dll => + ( + Path.GetFileName(dll).StartsWith("Speckle.Connectors.", StringComparison.OrdinalIgnoreCase) + || Path.GetFileName(dll).StartsWith("Speckle.Converters.", StringComparison.OrdinalIgnoreCase) + ) && !Path.GetFileName(dll).Contains("Test", StringComparison.OrdinalIgnoreCase) // Exclude test assemblies + ); + + foreach (var dll in dllFiles) + { + try + { + var assemblyName = AssemblyName.GetAssemblyName(dll); + if (!assemblies.Any(a => a.FullName == assemblyName.FullName)) + { + var loadedAssembly = Assembly.LoadFrom(dll); + assemblies.Add(loadedAssembly); + Console.WriteLine($"Loaded assembly: {loadedAssembly.FullName}"); + } + } + catch (BadImageFormatException) + { + Console.WriteLine($"Skipping invalid assembly: {dll}"); + } + catch (Exception ex) when (!ex.IsFatal()) + { + Console.WriteLine($"Failed to load assembly: {dll}. Error: {ex.Message}"); + } + } + } + + Console.WriteLine($"Solution directory {solutionDirectory}"); // Dynamically load assemblies from the solution directory // string? solutionDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);