我正在编写一个库,给定一个程序集,它会生成一个它的依赖程序集列表 - 包括依赖项的依赖项。预期的使用场景主要包括托管代码 (.NET) 程序集。
我计算这个依赖列表的方法如下:
- 创建一个临时的 AppDomain(代码)
- 在该 AppDomain(代码)中创建帮助程序类的实例
- 为我的初始程序集提供帮助:依赖树的根(代码)
- 在临时 AppDomain 的仅反射上下文(代码)中加载该程序集以进行检查
- 递归地寻找依赖关系
请注意,此帮助程序类是在仅引用 .NET 程序集的程序集中定义的;没有其他的。主库的程序集确实有对程序集的引用。 System.Reactive
我希望临时 AppDomain没有加载这些System.Reactive
程序集,但我收到一个错误提示。
API restriction: The assembly 'file:///X:\some-path\System.Reactive.Linq.dll' has already loaded from a different location. It cannot be loaded from a new location within the same appdomain.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
at System.Reflection.Assembly.ReflectionOnlyLoadFrom(String assemblyFile)
at DependencyResolver.AppDomainHelper.Util.AssemblyLoader.ReflectionOnlyLoadFromAssemblyPath(AssemblyName assembly, FileNotFoundException originalException) in DependencyResolver\DependencyResolver.AppDomainHelper\Util\AssemblyLoader.cs:line 96
at DependencyResolver.AppDomainHelper.Util.AssemblyLoader.ReflectionOnlyLoad(AssemblyName assembly) in DependencyResolver\DependencyResolver.AppDomainHelper\Util\AssemblyLoader.cs:line 67
at DependencyResolver.AppDomainHelper.Util.AssemblyLoader.ReflectionOnlyLoad(AssemblyName assembly)
at DependencyResolver.Resolver.GetAllDependenciesRecursive(AssemblyName start, Func`2 filter, Func`2 preProcess, Action`1 postProcess) in DependencyResolver\DependencyResolver\Resolver.cs:line 39
at DependencyResolver.Resolver.<>c__DisplayClass6.<GetAllDependenciesRecursive>b__5(AssemblyName an) in DependencyResolver\DependencyResolver\Resolver.cs:line 51
at System.Reactive.Linq.Observαble.Select`2._.OnNext(TSource value)
当我在一堆包含不同版本的System.Reactive.Linq.dll
.
如何确保我的临时 AppDomain 不会加载它不需要的任何内容?