Link to home
Start Free TrialLog in
Avatar of ol muser
ol muserFlag for United States of America

asked on

when is a referenced dll loaded?

Hi, In a CLR enabled VC++ (VS2008) project I believe loading one of the referenced DLL is crashing the application as it launches. Which has made me curious as to when referenced DLLs are loaded into the application's memory space. I used to think the referenced assemblies would be loaded only when they are needed. Or does it happen on application start-up. What is the best way to cut off these DLLs one by one to see which one is causing the crash? thanks!

Environment: Windows XP, VS 2008, .Net 3.5
Avatar of Easwaran Paramasivam
Easwaran Paramasivam
Flag of India image

Referenced DLL would be loaded when any of it's element is being used. This is for static way. Otherwise you could load reference using Assembly.Load() or Assembly.LoadFrom().

You could refer N number of references in your project but using only few of them in your application that won't degrade your application performance. But it is not advisable due to difficult for maintenance.  

In order to identify which Assembly causes crashing, better implement Exception caching. Better catch AppDomainException as well. This would avoid crashing. Log every method using NLog or some other logging mechanism. So that you come to know in which case it is crashing.
An application that crashes before executing Main usually does so because a dll is missing. The CLR check for the presence of referenced dlls before starting an application. Better to have an error when the application starts than in the middle of a long session of work, isn't it?

This type of error is hard to diagnose because it happens before your code has started executing, so no error trapping can get information about the error.

If you have a Debugger installed on the computer on which the application runs however, you have the option of dropping in the debugger while the system is sending error information to Microsoft (Error Reporting.jpg). You can install a copy of the free Visual Studio Express in order to get a debugger on a user's station if needed.

Going into Debug then gives you a clear indication of which dll is missing (FileNotFoundException.jpg)

In order for the debugger to work with running programs, you have to enable JIT Debugging in the copy of Visual Studio installed on the computer. This is done through Tools...Options...Debugging...Just-In-Time.
Error-Reporting.jpg
FileNotFoundException.jpg
ASKER CERTIFIED SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial