Solved

when is a referenced dll loaded?

Posted on 2013-01-31
3
404 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 33

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

910 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

16 Experts available now in Live!

Get 1:1 Help Now