How to catch for this error.

Jan 29 2008 6:34 PM

I get this exception when i am missing a dll file referenced in my project.

"************** Exception Text **************
System.IO.FileNotFoundException: File or assembly name Excel, or one of its dependencies, was not found.
File name: "Excel""  

Dim excelApp As New Excel.Application

Dim excelBook As Excel.Workbook = excelApp.Workbooks.Add

Dim excelWorksheet As Excel.Worksheet = CType(excelBook.Worksheets(1), Excel.Worksheet)

Its that code that fails when it is not there.

but even if I wrap the whole function in a try catch block it still won't handle it.  I always get an unhandled exception dialog box.

Now that I know what is causing it I would like to handle the error in a nice way so the user can fix it.

For the time being I even had to code a global error handler just to catch it but I can't leave that in a production app.