(Msg. 9) Posted: Tue Dec 02, 2008 9:16 am
Post subject: Re: Application.ActiveExplorer().Selection fails in C# application [Login to view extended thread Info.] Archived from groups: microsoft>public>outlook>interop (more info?)
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;
"Rune Jacobsen" <RuneJacobsen.DeleteThis@discussions.microsoft.com> wrote in message
news:8780C962-FA97-4107-AAB7-A35611880E9A@microsoft.com...
> Ken,
>
> Thanks for following up!
>
> I tried to do as you suggested, and reduce this to the simplest possible
> C#
> console application. Here is the complete source code for my mega advanced
> application:
>
> using System;
> using System.Collections.Generic;
> using System.Linq;
> using System.Text;
>
> using Outlook = Microsoft.Office.Interop.Outlook;
>
> 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);
>
> Console.WriteLine("{0} selected",
> app.ActiveExplorer().Selection.Count);
> }
> }
> }
>
> However, on the Console.WriteLine line I still get the
> System.AccessViolationException. It also says something about
> reading/writing
> to/from corrupted memory - not sure about the exact English wording as I
> get
> the error message already translated to my native norwegian.
>
> So, this is strange, right? Shouldn't this just work? >
> Thanks again!
(Msg. 10) Posted: Thu Dec 04, 2008 6:34 am
Post subject: Re: Application.ActiveExplorer().Selection fails in C# application [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
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
(Msg. 11) Posted: Fri Dec 05, 2008 9:46 am
Post subject: Re: Application.ActiveExplorer().Selection fails in C# application [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
Well, if this happens on more than one machine I'd rule out a bad memory
stick. Otherwise if this was limited to one machine I'd go for a possible
hardware problem.
For the starting Outlook using code if no UI is shown then obviously
ActiveExplorer() is going to be null unless you add UI. But if you're
getting the same access violation on the Explorers collection then it's not
that.
I'm not sure why you're getting access violations, I haven't run into that.
I'm afraid my only suggestion at this point is to open a case with MS
support and see what they turn up as a possible cause.
"Rune Jacobsen" <RuneJacobsen.DeleteThis@discussions.microsoft.com> wrote in message
news:55B478B5-13BC-43FA-9A5A-B865474A4585@microsoft.com...
> 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
All times are: Eastern Time (US & Canada) (change) Goto page Previous1, 2
Page 2 of 2
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum