Ken,
Thanks again for following up, and sorry about the late reply, have spent a
few days getting beaten up by customers on site.
I tried pasting your code into VS directly (just fixing the little ex -> err
thing), and the following happens when Outlook is running;
1. I can actually get the Explorer object using app.ActiveExplorer();
However, this object gives me access violations on most of its' properties.
2. exp.Selection causes a System.AccessViolationException
3. The ex.Message is "Forsøk på lesing fra eller skriving til beskyttet
minne. Dette er ofte en indikasjon på at annet minne er ødelagt." - this is
the same message I get all the time, basically. It is a norwegian translation
that roughly means "Attempt at reading from or writing to protected memory.
This is often an indication that other memory is broken".
4. Inside the catch block, the if statement throws with the same exception
on the app.Explorers object.
If I repeat the process with Outlook not running when I start the app in
debug mode (and usually having to kill the Outlook process as it refuses to
die on its own), app.ActiveExplorer() returns null, so I get a null reference
exception on exp.Selection. app.Explorers still returns the same
System.AccessViolationException.
Please note that I have tried to set macro security to "No security control
for macros" just to see if that would make a difference - and it didn't.
Any other ideas? I can experiment wildly with this developer machine if you
need me to.
Thanks again,
Rune
"Ken Slovak - [MVP - Outlook]" wrote:
> It is odd. I'd probably go a little deeper to try to find out where exactly
> that code is failing. See what happens with something like this:
>
> namespace OutlookTest
> {
> class Program
> {
> private static Outlook.Application app = null;
> private static Outlook.NameSpace ns = null;
>
> static void Main(string[] args)
> {
> app = new Outlook.Application();
> ns = app.GetNamespace("MAPI");
> ns.Logon("", "", false, false);
>
> try
> {
> Outlook.Explorer exp = app.ActiveExplorer();
> Console.WriteLine("{0} selected", exp.Selection.Count);
> }
> catch (Exception ex)
> {
> Console.WriteLine(err.Message);
> if (app.Explorers.Count > 0)
> {
> Console.WriteLine("Explorers.Count == " +
> app.Explorers.Count.ToString());
> }
> }
> }
> }
> }
>
> Do you get the same error if you don't have Outlook already running as when
> you do have it already running when your code executes?
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm