Outlook has stopped working on Windows 2008 Server

Add-in Express™ Support Service
That's what is more important than anything else

Outlook has stopped working on Windows 2008 Server
Code that works on XP and Windows 7 pcs crashes on 2008 Server 
jblitzie




Posts: 5
Joined: 2010-08-05
I've developed a .Net dll to manage Outlook folders for our application which is working well on XP and Windows 7 laptops running Office 2007. However, in our term server environment, we receive an error that Office has stopped working when the code performs a connect.


outlookApp = (ApplicationClass)Activator.CreateInstance(olType);
if (outlookApp != null)
{

    securityManager1.ConnectTo(outlookApp); <--- generates the error
    // switch OFF
    securityManager1.DisableOOMWarnings = true;

    object[] arguments = new object[] { "MAPI" };
    outlookNamespace = (NameSpace)outlookApp.GetType().InvokeMember("GetNamespace", BindingFlags.InvokeMethod, null, outlookApp, arguments);

    arguments = new object[] { defaultProfile, Missing.Value, Missing.Value, false };
    outlookNamespace.GetType().InvokeMember("Logon", BindingFlags.InvokeMethod, null, outlookNamespace, arguments);
    
    recipient = outlookNamespace.GetType().InvokeMember("CurrentUser", BindingFlags.GetProperty, null, outlookNamespace, null);
    outlookName = Convert.ToString(recipient.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, recipient, null));

    arguments = new object[] { OlDefaultFolders.olFolderInbox };
    outlookInbox = (MAPIFolder)outlookNamespace.GetType().InvokeMember("GetDefaultFolder", BindingFlags.InvokeMethod, null, outlookNamespace, arguments);

    if (outlookInbox == null)
    {
        outlookConnected = false;
        DisconnectOutlook(true);
        return outlookConnected;
    }

    outlookConnected = true;

    try
    {
        outlookMailBox = (MAPIFolder)outlookInbox.Parent;
    }
    catch (System.Exception ex) { }

    if (outlookMailBox == null)
    {
        outlookConnected = false;
        Marshal.ReleaseComObject(outlookInbox);
        outlookInbox = null;
        outlookNamespace.Logoff();
        DisconnectOutlook(true);
        return outlookConnected;
    }
    
    // Set the ExternalReferences key if running Office 2007
    SetExternalReferenceKey(true);

    Marshal.ReleaseComObject(outlookInbox);
    outlookInbox = null;
}
catch (System.Exception ex)
{
    MessageBox.Show("Message A" + "
" + ex.Message + ex.StackTrace.ToString());
    outlookConnected = false;
    DisconnectOutlook(true);
}
finally
{
    securityManager1.DisableOOMWarnings = false;
}


The securityManager1.ConnectTo(outlookApp); line is where the error is occurring.

Plus, it occurs only if Outlook is not already running when I run my application.

If I take out the references to the SecurityManager, Outlook runs fine, albeit with security warnings popping up.

Here's the error information:

Microsoft Office Outlook has stopped working.

Problem signature:
Problem Event Name: BEX
Application Name: OUTLOOK.EXE
Application Version: 12.0.6514.5000
Application Timestamp: 4a89dc70
Fault Module Name: unknown
Fault Module Version: 0.0.0.0
Fault Module Timestamp: 00000000
Exception Offset: 00000001
Exception Code: c0000005
Exception Dat a: 00000008
OS Version: 6.0.6002.2.2.0.16.7
Locale ID: 1033

Additional information about the problem:
LCID: 1033
Brand: Office12Crash
skulcid: 1033

After the error above, I also get:
Value does not fall within expected range.
at AddInExpress.Outlook.ISecurityManager2.Connect(Object vTarget)
at AddInExpress.OutlookSecurityManager.ConnectTo(Object outlookApp)
at OutlookWrapper.OutlookManager.ConnectOutlook() <-- my .Net class


Any assistance would be greatly appreciated.

Regards,

Jim
Posted 05 Aug, 2010 16:31:28 Top
Eugene Astafiev


Guest


Hello Jim,

Please make sure that you have logged in Outlook. For more information see the Logon method of the Namespace class.
Posted 06 Aug, 2010 08:24:42 Top
jblitzie




Posts: 5
Joined: 2010-08-05
Hi Eugene,

Thanks for the reply. In the code above, there is a Logon call:

arguments = new object[] { defaultProfile, Missing.Value, Missing.Value, false };
outlookNamespace.GetType().InvokeMember(\"Logon\", BindingFlags.InvokeMethod, null,
outlookNamespace, arguments);

Should this occur before the connect? (securityManager1.ConnectTo(outlookApp);)

Jim
Posted 06 Aug, 2010 08:49:06 Top
Eugene Astafiev


Guest


Jim,

Please try moving that code before you call the ConnectTo method.
Posted 06 Aug, 2010 10:09:14 Top
jblitzie




Posts: 5
Joined: 2010-08-05
Eugene,

Same error.

Here's the changed code...

outlookApp = (ApplicationClass)Activator.CreateInstance(olType);
if (outlookApp != null)
{
object[] arguments = new object[] { "MAPI" };
outlookNamespace = (NameSpace)outlookApp.GetType().InvokeMember("GetNamespace", BindingFlags.InvokeMethod, null, outlookApp, arguments);

arguments = new object[] { defaultProfile, Missing.Value, Missing.Value, false };
outlookNamespace.GetType().InvokeMember("Logon", BindingFlags.InvokeMethod, null, outlookNamespace, arguments);

securityManager1.ConnectTo(outlookApp);
// switch OFF
securityManager1.DisableOOMWarnings = true;

recipient = outlookNamespace.GetType().InvokeMember("CurrentUser", BindingFlags.GetProperty, null, outlookNamespace, null);
outlookName = Convert.ToString(recipient.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, recipient, null));
.
.
.
Posted 06 Aug, 2010 10:58:45 Top
Eugene Astafiev


Guest


Jim,

Ok. Now please try passing an explorer object to the ConnectTo method.
Posted 06 Aug, 2010 11:27:39 Top
jblitzie




Posts: 5
Joined: 2010-08-05
Eugene,

At that point in the program, I'm starting Outlook. There isn't an Explorer object created yet.

When my application runs, it will start up Outlook but Outlook stays hidden (minimized to the system tray). If a user selects an Outlook folder icon in my app, I then show Outlook, creating an Explorer if necessary.

Jim
Posted 06 Aug, 2010 11:52:34 Top
jblitzie




Posts: 5
Joined: 2010-08-05
Eugene,

After my last post, I got thinking more about your suggestion. What I did was: if there are no explorers when I'm trying to connect (Outlook isn't yet running), I create a new one (code below). This seems to have corrected the problem and it is now working on the 2008 Server.

Thanks for the suggestions, :)

Regards,

Jim

outlookApp = (ApplicationClass)Activator.CreateInstance(olType);
if (outlookApp != null)
{

object[] arguments = new object[] { "MAPI" };
outlookNamespace = (NameSpace)outlookApp.GetType().InvokeMember("GetNamespace", BindingFlags.InvokeMethod, null, outlookApp, arguments);

arguments = new object[] { defaultProfile, Missing.Value, Missing.Value, false };
outlookNamespace.GetType().InvokeMember("Logon", BindingFlags.InvokeMethod, null, outlookNamespace, arguments);

arguments = new object[] { OlDefaultFolders.olFolderInbox };
outlookInbox = (MAPIFolder)outlookNamespace.GetType().InvokeMember("GetDefaultFolder", BindingFlags.InvokeMethod, null, outlookNamespace, arguments);

// If no explorer...let's create one for to pass to the SecurityManager.
if (outlookApp.Explorers.Count == 0)
{
try
{
outlookExplorer = outlookApp.Explorers.Add(outlookInbox, OlFolderDisplayMode.olFolderDisplayNormal);
newExplorer = true;
}
catch (System.Exception ex) { }
}
else
outlookExplorer = this.outlookApp.ActiveExplorer();

if (outlookExplorer == null)
{
outlookConnected = false;
DisconnectOutlook(true);
return outlookConnected;
}

securityManager1.ConnectTo(outlookExplorer);
// switch OFF
securityManager1.DisableOOMWarnings = true;

recipient = outlookNamespace.GetType().InvokeMember("CurrentUser", BindingFlags.GetProperty, null, outlookNamespace, null);
outlookName = Convert.ToString(recipient.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, recipient, null));

if (outlookExplorer != null && newExplorer == true)
{
outlookExplorer.Close();
}
Posted 06 Aug, 2010 14:39:41 Top
Eugene Astafiev


Guest


You broke the ice, Jim!

Thank you for sharing the solution.
Posted 12 Aug, 2010 03:51:48 Top