Note that there are some explanatory texts on larger screens.

plurals
  1. POTesting if outlook is installed with C# exception-handling
    primarykey
    data
    text
    <p>I have a section of my application that allows for people to send an email of the generated text. My current problem is that when they load the form with the text, it throws an unhandled exception System.IO.FileNotFound when the user does not have outlook installed. On the load of the form, I try to determine is they have outlook installed.</p> <pre><code>try{ //Assembly _out = Assembly.Load("Microsoft.Office.Interop.Outlook"); Assembly _out = Assembly.Load("Microsoft.Office.Interop.Outlook, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"); //Microsoft.Office.Interop.Outlook.Application _out = new Microsoft.Office.Interop.Outlook.Application(); //Microsoft.Office.Interop.Outlook.Application _out = new Microsoft.Office.Interop.Outlook.Application(); } </code></pre> <p>Above is the code I have been trying. On the computer where I am developing, if the assembly name is off the catch statements will catch it. However, when I test it on an XP machine with no outlook, it throws the error and stops the loading of the form events.</p> <p>Every catch statement I have tried (Catch all didn't even work):</p> <pre><code> catch (System.IO.FileLoadException) { _noOutlook = true; type = "FILE-LOAD"; } catch (System.IO.FileNotFoundException) { _noOutlook = true; type = "FILE-NOT-FOUND"; } catch (System.IO.IOException) { _noOutlook = true; type = "IO"; } catch (System.Runtime.InteropServices.COMException) { _noOutlook = true; type = "INTEROP"; } catch (System.Runtime.InteropServices.InvalidComObjectException) { _noOutlook = true; type = "INTEROP-INVALIDCOM"; } catch (System.Runtime.InteropServices.ExternalException) { _noOutlook = true; type = "INTEROP-EXTERNAL"; } catch (System.TypeLoadException) { _noOutlook = true; type = "TYPELOAD"; } catch (System.AccessViolationException) { _noOutlook = true; type = "ACCESVIOLATION"; } catch (WarningException) { _noOutlook = true; type = "WARNING"; } catch (ApplicationException) { _noOutlook = true; type = "APPLICATION"; } catch (Exception) { _noOutlook = true; type = "NORMAL"; } </code></pre> <p>I'm looking for a method that will work (hopefully so I could use one code to work for Outlook 2010 &amp; 2007) without having to check the registry / exact file path.</p> <p>So a couple things I am wondering is why XP is even throwing the errors and not catching them, since it throws the FileNotFound when I have a catch for it, and what is a good method to determine if the outlook interop object will work.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload