.NET Framework Bookmark and Share   
 index > Building Development and Diagnostic Tools for .Net > How to reflection-only load dependencies in another folder?
 

How to reflection-only load dependencies in another folder?

Hi,

I'm currently writing some kind of managed/unmanaged DependencyWalker in C#. I already shipped around many cliffs like enumerating thenative dependencies of an assembly without having reflection available.

My current problem is reflection only loading of the managed dependencies of an assembly in another folder. Given a file structure like

\walker\walker.exe

\assemblies\assembly1.dll

\assemblies\assembly2.dll

\assemblies\native.dll

my walking application is walker.exe. The user selects the managed assembly \assemblies\assembly1.dll and it gets loaded via Assembly.ReflectionOnlyLoadFrom(). That works fine. I can now enumerate its referenced assemblies and its imported native dlls.

Let's assume now that assembly1 depends on assembly2 and that depends on the native dll.

When I now try to load the referenced assemblies by full name, I get load failures, as they are lying in the \assemblies folder and my current AppDomain is \walker based.

I subscribed to the ReflectionOnlyAssemblyResolve event and get callbacks for only some of the assemblies. I fix them and they can be ReflectionOnlyLoaded. For the remaining assemblies I get FileNotFoundExceptions. I suspect these are dlls with native imports that can only be resolved running from \assemblies.

I experimented with creating a new AppDomain with different base directorybut didn't come further. As AppDomain has only Load() and no ReflectionOnlyLoad()/ReflectionOnlyLoadFrom() I would have to execute code in the other domain. For that I have to load my code into the other domain, so I have to load my exe there. But AppDomain has not LoadFrom() either, so I'm stuck if I don't want to copy an assembly there or emit code into the other domain.

Any ideas?

Cheers,

Thomas

thomas_schmidt
I strongly suggest that you pursue the separate AppDomain path with a BaseDirectory in the "assemblies" folder. You will have to execute code inside the domain - for that you have two alternatives. Either you could make a temporary copy of the entire directory structure somewhere, copy your EXE there, do the reflection process and then delete the temporary directory structure; OR you could simply GAC your EXE (or some auxiliary assembly) and then it will be loaded in the secondary AppDomain without you having to copy it anywhere.
Sasha Goldshtein
I strongly suggest that you pursue the separate AppDomain path with a BaseDirectory in the "assemblies" folder. You will have to execute code inside the domain - for that you have two alternatives. Either you could make a temporary copy of the entire directory structure somewhere, copy your EXE there, do the reflection process and then delete the temporary directory structure; OR you could simply GAC your EXE (or some auxiliary assembly) and then it will be loaded in the secondary AppDomain without you having to copy it anywhere.
Sasha Goldshtein

You can use google to search for other answers

Custom Search

More Threads

• Creating A Helper Thread
• Trouble with VectoredExceptionHandler and ICorDebugProcess->Stop method
• Memory Reading from a .NET program
• VS2010CTP: MiniDump-Support displays the wrong callstack
• vs2005 - timing
• ICDType <-> MD Type signatures
• Compiling a single .CS File In a Project
• Leak DebugDiag help
• Can I know how to get some sample class diagram for c# projects?
• How to get a full stacktrace from a crashed mixed mode exe/dll ?