44using System . Linq ;
55using System . Reflection ;
66using System . Text . RegularExpressions ;
7+ using Microsoft . DotNet . PlatformAbstractions ;
8+ using Microsoft . Extensions . DependencyModel ;
79using Shuttle . Core . Contract ;
810using Shuttle . Core . Logging ;
911
@@ -35,7 +37,7 @@ public string AssemblyPath(Assembly assembly)
3537
3638 public Assembly GetAssembly ( string assemblyPath )
3739 {
38- var result = AppDomain . CurrentDomain . GetAssemblies ( )
40+ var result = RuntimeAssemblies ( )
3941 . FirstOrDefault ( assembly => AssemblyPath ( assembly )
4042 . Equals ( assemblyPath , StringComparison . InvariantCultureIgnoreCase ) ) ;
4143
@@ -102,7 +104,7 @@ public Assembly FindAssemblyNamed(string name)
102104 hasFileExtension = true ;
103105 }
104106
105- var result = AppDomain . CurrentDomain . GetAssemblies ( )
107+ var result = RuntimeAssemblies ( )
106108 . FirstOrDefault ( assembly => assembly . GetName ( )
107109 . Name . Equals ( assemblyName , StringComparison . InvariantCultureIgnoreCase ) ) ;
108110
@@ -186,9 +188,7 @@ private IEnumerable<Assembly> GetMatchingAssemblies(Regex expression, string fol
186188
187189 public IEnumerable < Assembly > GetMatchingAssemblies ( string regex )
188190 {
189- var expression = new Regex ( regex , RegexOptions . IgnoreCase ) ;
190- var assemblies = new List < Assembly > ( AppDomain . CurrentDomain . GetAssemblies ( )
191- . Where ( assembly => expression . IsMatch ( assembly . FullName ) ) ) ;
191+ var assemblies = new List < Assembly > ( RuntimeAssemblies ( ) ) ;
192192
193193 foreach (
194194 var assembly in
@@ -215,7 +215,19 @@ var assembly in
215215 return assemblies ;
216216 }
217217
218- public IEnumerable < Type > GetTypes < T > ( )
218+ public IEnumerable < Assembly > RuntimeAssemblies ( )
219+ {
220+ var result = new List < Assembly > ( ) ;
221+
222+ foreach ( var runtimeAssemblyName in DependencyContext . Default . GetRuntimeAssemblyNames ( RuntimeEnvironment . GetRuntimeIdentifier ( ) ) )
223+ {
224+ result . Add ( Assembly . Load ( runtimeAssemblyName ) ) ;
225+ }
226+
227+ return result ;
228+ }
229+
230+ public IEnumerable < Type > GetTypes < T > ( )
219231 {
220232 return GetTypes ( typeof ( T ) ) ;
221233 }
0 commit comments