none
Outlook crashes after throwing "Attempted to access an unloaded AppDomain." exception RRS feed

  • Question

  • Hello All,
    I've developed a outlook addin with c# 3.5, VSTO and Visual Studio 2008 for Outlook 2003.

    The code works fine almost all time but sometimes Outlook crashes after throwing "Attempted to access an unloaded AppDomain." exception

    Exception stackTrace:
    03/17/2011 8:17:05 AM : DoSomething_Outlook_Startup: exception:The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl, DoSomething Notify Policy]) failed: Attempted to access an unloaded AppDomain. (Strategy type ConfiguredObjectStrategy, index 2)

       at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception exception, String policyName, ExceptionPolicyFactory factory)

       at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName, ExceptionPolicyFactory policyFactory)

       at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName)

       at DoSomething.OutlookAddIn.DoSomething_Outlook.PaintMainMenu(Application objApp)

       at DoSomething.OutlookAddIn.DoSomething_Outlook.DomeSomething_Outlook_Startup(Object sender, EventArgs e)


    Outlook Addin Code:

    //Startup handler
    private void DoSomeThing_Outlook_Startup(object sender, System.EventArgs e)
            {
                try
                {


                    applicationObject = this.Application;
    ..
    ..
    ..
                        PaintMainMenu(applicationObject);


                }
                catch (Exception ex)
                {
      //Exception being thrown from PaintMainMenu is handled here
      //
                    Logger.Log("DoSomething_Outlook_Startup: exception:" + ex.Message + Environment.NewLine + ex.StackTrace);
                    AddInGlobal.ProcessUnhandledException(ex);
                }
            }

    //Method to add DoSomething menu item to File menu
    private void PaintMainMenu(Outlook.Application objApp)
            {
                try
                {

                    objApp.ActiveExplorer().CommandBars["File"].Reset();


                    menubar = objApp.ActiveExplorer().CommandBars.ActiveMenuBar;
                    Office.CommandBarPopup cbc = (Office.CommandBarPopup)
                               menubar.FindControl
                               (Office.MsoControlType.msoControlPopup, 30002, Missing.Value, Missing.Value, Missing.Value);


                    if ((menubar != null))
                    {
                        _DoSomething = (Office.CommandBarButton)cbc.Controls.Add(
                                     Office.MsoControlType.msoControlButton, Missing.Value,
                                     Missing.Value, 6, true);

                        if (_DoSomething != null)
                        {
                            _DoSomething.Tag = AddInConstants.C_Menubar_Menu_Tag;
                            _DoSomething.Caption = AddInConstants.C_Menubar_Menu_Caption;

                            _DoSomething.Click += new _CommandBarButtonEvents_ClickEventHandler(DoSomething_Click);
       _DoSomething.Enabled = false;
                        }
                    }
                }
                catch (Exception ex)
                {
      //below line throws "Attempted to access an unloaded AppDomain."
                    bool rethrow = ExceptionPolicy.HandleException(ex, AddInConstants.C_Global_NotifyPolicy);
                    if (rethrow)
                        throw;
                }
            }

    Monday, March 21, 2011 7:11 AM

All replies

  • Hi Hemant,

    Thanks for posting in the MSDN Forum.

    Would you please clarify the some of the variables’ mean such as _DoSomthing,  AddInGlobal? And would you tell me when the add-in will take this exception? Did you run some specific program when you take it?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, March 23, 2011 2:23 AM
    Moderator
  • Hello Tom,

    Thanks for replying to the message.

    _DoSomething is a class level variable of type Office.CommandBarButton defined in Outlook Addin project. I use this variable to add a menu option to File menu of active outlook Explorer.

    AddInGlobal is a static class which has a function to handle unhandled exceptions. This class is defined in same Outlook Addin project. Actually there are 2 log files one for office applications and one for our application's window based client. so this AddInGlobal adds entry to the other log.

    Its an Outlook addin project and on startup function of this addin i add "Some Menu Option" to File menu of the active Outlook explorer. The exception occurs when Outlook starts and starts loading my addin. There is no external call to any program from this function.

    Thanks,

    Hemant

    Wednesday, March 23, 2011 10:05 AM
  • Hi Hemant,

    It’s based on the exception messages that you provide, that there are some of the assemblies weren’t loaded.

    Would you please provide more exception messages to me, so that we’re able to analysis these message to find out which place will throw this exception.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, March 28, 2011 7:05 AM
    Moderator