View Full Version : file not found exception

10-13-2003, 04:08 PM
OK - this is more of a general .net question than specifically ASP.NET...

Am trying to build a little app that adds items to Outlook if it's installed... which works fine if it is...

For the purposes of demonstrating my problem I've created a 1 button form which does a test on clicking the button.

Am trying to extablish whether Outlook is installed, by using the following Try, Catch
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

End Sub

Private Sub testOutlook()
Dim objApp As Outlook.Application

objApp = New Outlook.Application()
Me.Button1.Text = "Outlook found"

Catch e As System.IO.FileNotFoundException
Me.Button1.Text = "Outlook not found"

objApp = Nothing

End Try

End Sub
Problem is that the Try, Catch block is not catching the exception when run on a machine that doesn't have Outlook installed so I end up with an error dialog, not a message box with a cleaner error message.

Anyone got any ideas?


10-13-2003, 05:04 PM
What does the error message say?

10-13-2003, 05:11 PM
Here's the error message - in full...
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.IO.FileNotFoundException: File or assembly name Interop.Outlook, or one of its dependencies, was not found.
File name: "Interop.Outlook"
at testOutlook.Form1.testOutlook()
at testOutlook.Form1.Button1_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Fusion log follows:
=== Pre-bind state information ===
LOG: DisplayName = Interop.Outlook, Version=, Culture=neutral, PublicKeyToken=null
LOG: Appbase = D:\
LOG: Initial PrivatePath = NULL
Calling assembly : testOutlook, Version=1.0.1381.24261, Culture=neutral, PublicKeyToken=null.

LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Post-policy reference: Interop.Outlook, Version=, Culture=neutral, PublicKeyToken=null
LOG: Attempting download of new URL file:///D:/Interop.Outlook.DLL.
LOG: Attempting download of new URL file:///D:/Interop.Outlook/Interop.Outlook.DLL.
LOG: Attempting download of new URL file:///D:/Interop.Outlook.EXE.
LOG: Attempting download of new URL file:///D:/Interop.Outlook/Interop.Outlook.EXE.

************** Loaded Assemblies **************
Assembly Version: 1.0.3300.0
Win32 Version: 1.0.3705.288
CodeBase: file:///c:/winnt/microsoft.net/framework/v1.0.3705/mscorlib.dll
Assembly Version: 1.0.1381.24261
Win32 Version: 1.0.1381.24261
CodeBase: file:///D:/testOutlook.exe
Assembly Version: 1.0.3300.0
Win32 Version: 1.0.3705.288
CodeBase: file:///c:/winnt/assembly/gac/system.windows.forms/1.0.3300.0__b77a5c561934e089/system.windows.forms.dll
Assembly Version: 1.0.3300.0
Win32 Version: 1.0.3705.288
CodeBase: file:///c:/winnt/assembly/gac/system/1.0.3300.0__b77a5c561934e089/system.dll
Assembly Version: 1.0.3300.0
Win32 Version: 1.0.3705.288
CodeBase: file:///c:/winnt/assembly/gac/system.drawing/1.0.3300.0__b03f5f7f11d50a3a/system.drawing.dll
Assembly Version: 1.0.3300.0
Win32 Version: 1.0.3705.288
CodeBase: file:///c:/winnt/assembly/gac/system.xml/1.0.3300.0__b77a5c561934e089/system.xml.dll
Assembly Version: 7.0.3300.0
Win32 Version: 7.00.9502
CodeBase: file:///c:/winnt/assembly/gac/microsoft.visualbasic/7.0.3300.0__b03f5f7f11d50a3a/microsoft.visualbasic.dll

************** JIT Debugging **************
To enable just in time (JIT) debugging, the config file for this
application or machine (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging

For example:

<system.windows.forms jitDebugging="true" />

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the machine
rather than being handled by this dialog.

Ignore the bits about JIT debugging - am having to test on a remote machine that doesn't have outlook on...

To use outlook from the Windows form you have to add a reference to Outlook. I'd assumed that you could use a Try/Catch block and other sites on the web that I've looked at since trying this have said pretty much the same so am somewhat confused as to why it's throwing this error when I'm using the Try/Catch block with a specific expception in the Catch???