views:

710

answers:

5

Essentially need to read the dependencies programmatically without loading the assembly itself, as then you can't unload them

+2  A: 

Kumar,

You CAN unload .Net DLLs but you have to use the AppDomain object to load them in the first place and then again to unload.

Take a look: http://msdn.microsoft.com/en-us/library/system.appdomain(VS.80).aspx

If you still want to avoid this type of process, i suppose you could parse the the DLL yourself but that would be much more work than using the AppDomain i think.

-p

Paul Sasik
The problem is resolving the dependencies of the dll in the new AppDomain sandboxsomehow, sandBox.AssemblyResolve += new ResolveEventHandler(reh)generates an error saying the current assembly not found ???any clues ?
Kumar
A: 

Hope you are expecting Ildasm.exe (intermediate language disassembler)

http://msdn.microsoft.com/en-us/library/aa309387(VS.71).aspx

anishmarokey
sorry did not make it clear earlier....looking for programmatic access
Kumar
+1  A: 

2 solutions come to my mind, although I think there's easier way (which I forgot or don't know :) ):
1. Load your assemblies using some additional AppDomain that you can create. Unloading whole AddDomain will also unload loaded assemblies (but only those, which were loaded using this AppDomain).
2. Use some api, for example CCI that allows you to look inside managed dll's without loading it using reflection mechanism.

Ravadre
thx, will look into cci, the 1st option doesn't work due to dependencies
Kumar
looking at it and going nowhere...the only sample i found is http://www.codeproject.com/KB/recipes/Not_Used_Analysis.aspx but it's old and doesn't compile
Kumar
i got it working with Cecil but would like to use CCI since it's used internally by MS and is likely to be more current
Kumar
There are 3 CCI related projects on codeplex, each with it's own samples (ranges from inspecting some resources to mini compiler), they are fairly hard to understand (I think authors are aware of the fact, that they need to introduce some tutorials on this one :) ), but you could check those. Personally, I'm interested in rewriting my compiler (based on reflection) to CCI, but I'm waiting for more informations on libraries (tutorials, books?).
Ravadre
A: 

I'm sure someone will correct me if I'm wrong, but isn't the manifest just another resource in the DLL? If so, you can read it just like any other resource.

Here is an open source tool that lets you explore a DLLs resources:

http://www.wilsonc.demon.co.uk/d10resourceeditor.htm

And sure enough, I can see embedded manifests with it.

So, load the DLL using LoadLibrary() and go resource hunting.

Daniel Paull
LoadLibrary() does not worked with managed dll's from what i seem to have read earlier
Kumar
What do you mean by "does not work"?
Daniel Paull
+1  A: 

found this System.Reflection.Assembly.ReflectionOnlyLoadFrom(path) does the trick

Kumar