InfernumDeus
InfernumDeus

Reputation: 1202

How to prevent application from crashing when .dll is missing?

I want my program in case of missing .dll file to notify user about this fact instead of just crashing with FileNotFoundException reffering to this .dll.

This library is included to the project via refference.

Exception is thrown even before any of my code is executed so I can't hadle it.

Upvotes: 0

Views: 532

Answers (2)

TheGeneral
TheGeneral

Reputation: 81493

Your only 2 options are (as far as i know)

  • You need to load the dll dynamically and reflect what you need
  • Write a loader app to check for the dll before starting your app

This question may get you started on option one

Loading DLLs at runtime in C#

However : i guess its just easier to make sure they have the dll or include it in the build

Upvotes: 1

rahulaga-msft
rahulaga-msft

Reputation: 4154

During application start up, you can register app domain for any unhandled exception as :

AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

Your handler should take care of showing appropriate message to user.

Upvotes: 0

Related Questions