fix: filter domain assembly scans to Default ALC to prevent type identity mismatches

Plugin assemblies loaded via PluginHost into isolated AssemblyLoadContexts
produce distinct types even from the same DLL. When AppDomain.GetAssemblies()
returns both Default and plugin-ALC copies, DI registration and IOptions<T>
resolution silently fail (e.g. ValkeyTransportOptions defaulting to localhost).

Applied AssemblyLoadContext.Default filter to all 7 assembly discovery sites:
- MessagingServiceCollectionExtensions (transport plugin scan)
- StellaRouterIntegrationHelper (transport plugin loader)
- Gateway.WebService Program.cs (startup transport scan)
- GeneratedEndpointDiscoveryProvider (endpoint provider scan)
- ReflectionEndpointDiscoveryProvider (endpoint attribute scan)
- ServiceCollectionExtensions (schema provider scan)
- MigrationModulePluginDiscovery (migration plugin scan)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
master
2026-03-04 14:01:12 +02:00
parent aaad8104cb
commit 7bafcc3eef
27 changed files with 32 additions and 634 deletions

View File

@@ -72,12 +72,12 @@ internal static class MigrationModulePluginDiscovery
private static IEnumerable<IMigrationModulePlugin> DiscoverPlugins()
{
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().OrderBy(static a => a.FullName, StringComparer.Ordinal))
// Filter to Default ALC to avoid type identity mismatches from isolated plugin ALCs.
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()
.Where(static a => !a.IsDynamic
&& AssemblyLoadContext.GetLoadContext(a) == AssemblyLoadContext.Default)
.OrderBy(static a => a.FullName, StringComparer.Ordinal))
{
if (assembly.IsDynamic)
{
continue;
}
foreach (var type in GetLoadableTypes(assembly))
{