Solved

when is a referenced dll loaded?

Posted on 2013-01-31
3
414 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 34

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

752 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