Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

when is a referenced dll loaded?

Posted on 2013-01-31
3
Medium Priority
?
422 Views
Last Modified: 2013-02-17
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
0
Comment
Question by:Mydeen Yussouf
3 Comments
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 38839816
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.
0
 
LVL 40
ID: 38840525
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
0
 
LVL 35

Accepted Solution

by:
sarabande earned 2000 total points
ID: 38840556
you may have a look to event viewer (eventvwr.exe) where a failed loading of a dll might have caused a log entry.

you also could start the application from command window where a failed dll load may cause a message with (for example) error 126.

if both fails to give a hint what is going wrong you may add a message box to the main or start function of your program. if that message pops up it does not fail in the initial phase what woulkd mean it did not fail by loading the dlls where you linked against a import library (what is the normal case). it still could fail by loading a dll dynamically at runtime (by call of LoadLibrary)  but it also could bve a simple access violation by using a wrong or zero-valued pointer. to find the solution you might use message boxes or stored log messages (always open and close the logfile for each call) which you placed into the code to narrow down the last successful call of your own code.


Sara
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Loops Section Overview

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question