Assembly

J

Jeffrey

hello,


how do i get an assembly for a process which is not the own process.
and i also do not want to load a new assembly.


please no answers with Load, LoadFrom or GetExecutingAssembly.


jeff
 
J

Jon Skeet [C# MVP]

Jeffrey said:
how do i get an assembly for a process which is not the own process.
and i also do not want to load a new assembly.

please no answers with Load, LoadFrom or GetExecutingAssembly.

Sorry, it's not very clear what you mean. What do you actually want to
do? What do you mean by "get an assembly"? Do you mean you want to know
which assemblies have been loaded into a process?
 
J

Jeffrey

yes, i want to know which assemblies have been loaded into a process.
then i will get the instances of the assemblies.

a example. please don't care about the processid . the processid is not
the problem, i want the assemblies for a process given by processid and
i am looking how to write the function GetAssemblyfromPID(pid).



//pid =ProcessID
Assembly[] asm = GetAssemblyfromPID(pid)
 
J

Jon Skeet [C# MVP]

Jeffrey said:
yes, i want to know which assemblies have been loaded into a process.
then i will get the instances of the assemblies.

Right. At least the problem is clear now - unfortunately, I don't know
the answer. I don't believe there's a .NET way of doing it - you'll
need to use interop, I suspect, to find out which DLLs have been
loaded, and then find out which of those DLLs are .NET assemblies.
 
E

erick

If you want to know which assemblies are loaded in a certain process you
can just get the Modules from the Process by getting a handle of the process
itself.

System.Diagnostics.Process[] Processes = System.Diagnostics.Process.GetProcesses();
System.Diagnostics.Process aspnetProcess = null;
foreach(System.Diagnostics.Process process in Processes )
{
if(process.ProcessName.Equals("aspnet_wp"))
{
aspnetProcess = process;
break;
}
}
foreach(System.Diagnostics.ProcessModule module in aspnetProcess.Modules )
{
System.Diagnostics.Debug.WriteLine(module.FileName);
}


After that you have the path, so you can do whatever you want with them.
If you dont want to load them into the current appdomain you will have to
use AssemblyName.GetAssemblyName(...). But if it fails, it is not a .NET
assembly. There are more elegant ways of doing that but i am not sure what
you are working on.


Erick Sgarbi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top