Solved

when is a referenced dll loaded?

Posted on 2013-01-31
3
400 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:olmuser
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 32

Accepted Solution

by:
sarabande earned 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now