From 22e4484559c9e4971d627ce01d0a45d4dd0d85d4 Mon Sep 17 00:00:00 2001 From: Laszlo Paillat Date: Wed, 23 Oct 2024 14:57:41 +0200 Subject: [PATCH] fixed plugins loading in certain context (fixes #145 thanks to @a10r) --- documentation/NEXT_RELEASENOTES.txt | 3 ++- .../DefaultDocumentation.Common/Generator.cs | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/documentation/NEXT_RELEASENOTES.txt b/documentation/NEXT_RELEASENOTES.txt index 17c3b613..11b9698a 100644 --- a/documentation/NEXT_RELEASENOTES.txt +++ b/documentation/NEXT_RELEASENOTES.txt @@ -22,4 +22,5 @@ - fixed unhandled xml elements not rendering as is in markdown (fixes #126) - fixed issue with list rendering - fixed enum fields to respect code order (fixes #131) -- fixed c and see elements with leading and trailing linebreak chars (fixes #113) \ No newline at end of file +- fixed c and see elements with leading and trailing linebreak chars (fixes #113) +- fixed plugins loading in certain context (fixes #145 thanks to @a10r) \ No newline at end of file diff --git a/source/DefaultDocumentation.Common/Generator.cs b/source/DefaultDocumentation.Common/Generator.cs index 1623d0e2..57194efc 100644 --- a/source/DefaultDocumentation.Common/Generator.cs +++ b/source/DefaultDocumentation.Common/Generator.cs @@ -89,6 +89,31 @@ private Generator(Target loggerTarget, IRawSettings settings) GetSetting(nameof(settings.LinksBaseUrl)), GetSetting(nameof(settings.ExternLinksFilePaths))); + AppDomain.CurrentDomain.AssemblyResolve += (object sender, ResolveEventArgs args) => + { + AssemblyName assemblyName = new(args.Name); + + Assembly? loadedAssembly = Array.Find(((AppDomain)sender).GetAssemblies(), assemby => assemby.GetName().Name.Equals(assemblyName.Name, StringComparison.OrdinalIgnoreCase)); + + if (loadedAssembly?.GetName() is AssemblyName loadedAssemblyName + && loadedAssemblyName.Version != assemblyName.Version) + { + string message = $"using {assemblyName.Name} version {loadedAssemblyName.Version} instead of version {assemblyName.Version}, may cause issue"; + + if (loadedAssemblyName.Version.Major == assemblyName.Version.Major) + { + // there shouldn't be any breaking changes + _logger.Info(message); + } + else + { + _logger.Warn(message); + } + } + + return loadedAssembly; + }; + _context = new GeneralContext( _configuration, ((Assembly[])[