Я разработал надстройку для Outlook с c # 3.5, VSTO и Visual Studio 2008 для Outlook 2003.
Код работает нормально почти все время, но иногда Outlook вылетает после выдачи «Попытка доступа к незагруженному домену приложения». исключение
Исключение 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:
//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);
}
}
//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;
}
}
Спасибо заранее,
Hemant