I'm writing a library that, given an assembly, produces a list of it's dependency assemblies - including dependencies' dependencies. The intended usage scenario includes mostly managed code (.NET) assemblies.
My approach to computing this dependency list is the following:
- Create a temporary AppDomain (code)
- Create an instance of a helper class in that AppDomain (code)
- Feed that helper my initial assembly: the root of the dependency tree (code)
- Load that assembly for inspection in the temporary AppDomain's reflection-only context (code)
- Go after dependencies recursively
Please observe that this helper class is defined in an assembly that only references .NET assemblies; nothing else.
The main library's assembly does have references to System.Reactive
assemblies.
I would expect the temporary AppDomain to not have loaded these System.Reactive
assemblies, but I'm getting an error that suggests otherwise.
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)
This happens when I use the library on a pile of assemblies that contains a different version of System.Reactive.Linq.dll
.
How can I make sure my temporary AppDomain will not load anything it doesn't need?