From 41e0d2d926ba1d56952317afc491211eaf65e9eb Mon Sep 17 00:00:00 2001 From: Thomas Fuchs Date: Wed, 30 Aug 2023 11:38:28 +0200 Subject: [PATCH] Fix LoadComponents for private types with missing reference --- src/Moryx.Container/CastleContainer.cs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Moryx.Container/CastleContainer.cs b/src/Moryx.Container/CastleContainer.cs index 40f1ee2a0..b1a12edd6 100644 --- a/src/Moryx.Container/CastleContainer.cs +++ b/src/Moryx.Container/CastleContainer.cs @@ -160,7 +160,28 @@ public virtual void LoadComponents(Predicate condition) where T : class { _knownTypes = ReflectionTool.GetAssemblies() .Where(a => a.GetCustomAttribute() == null) - .SelectMany(a => a.GetTypes()) + .SelectMany(a => + { + // TODO: Replace with exported types in MORYX 8 + try + { + // This should only return exported types + return a.GetTypes(); + } + catch + { + // Fall back to exported types in case of exception + try + { + return a.GetExportedTypes(); + } + catch + { + // Give up + return new Type[0]; + } + } + }) .Where(t => t.GetCustomAttribute(true) != null).ToArray(); }