Memory handling & loading/unloading DLLs

G

Guest

Hello,
I would like to know how exactly works loading/unloading of libraries in
..NET (1.1). I have an assembly X which references assembly Y. If no type from
Y is used and no method to Y is called, is Y loaded ? May a dll be ever
unloaded ? And how it works if managed code uses unmaneged libraries ?

The background of my question is that we are currently solving crashing of
our application written in .NET which uses DB2 Data managed provider from
HIS2004. We have DataAccess layer which is able to use SQL Server or/and DB2.
The functionality for DB2 is never used in the application, so DB2 Data
provider assembly and I expect no one of its dependant native modules from
HIS should be loaded. But using Debugging Tools for Windows and ADPlus script
shows that those DLLs are unloaded. Later then, in logging library is used
call System.Diagnostic.Process.GetCurrentProcess().ProcessName to get process
name used in log entry. This call causes handling of some performance
counters probably in the unloaded DLLs. This is what we got from memory dump.
There is no mention about Performance counters logic in porperty ProcessName
in MSDN. However, with this knowledge I found the dependency on Performance
counters by Google. But still I'd like to know the library handling in .NET.

Thanks,
eXavier
 
W

Wei-Dong XU [MSFT]

Hi,

Currently I am finding one support professional for you on this issue. If
any update, we will reply here at the first time.

Best Regards,
Wei-Dong XU
Microsoft Product Support Services
This posting is provided "AS IS" with no warranties, and confers no rights.
It is my pleasure to be of assistance.
 
P

Peter Huang [MSFT]

Hi

If the there is nothing in the assembly is used, the assembly will not be
loaded even if in the compiling time, the assembly is referenced. So do
with the unmanaged dll, it will be loaded when our P/Invoke code is going
to call its exported dll.
We can not unload a dll is unloaded except we unload the whole appdomain.

private void Form1_Load(object sender, System.EventArgs e)
{
AppDomain.CurrentDomain.AssemblyLoad+=new
AssemblyLoadEventHandler(CurrentDomain_AssemblyLoad);
}

private void CurrentDomain_AssemblyLoad(object sender,
AssemblyLoadEventArgs args)
{
System.Diagnostics.Debug.WriteLine(args.LoadedAssembly.FullName);
}

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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