none
Word Add-In Disappear RRS feed

  • Question

  • Hi,

    We created word Add-In in .net 2008 for office 2007, but that get disappear quite often, we see that is listed in the “Disable Application Add-Ins” But we are unable to Enable this, we have to uninstall and install every time this happen.

     

    Can someone guide me why this is happening?

     

    Thank you so much for your help in Advance.


    ARUN
    Monday, July 4, 2011 1:36 PM

Answers

  • Hi Arun

    That's very difficult to say at this remove. As I mentioned, all you can do is try various things. Possibly the problem comes from trying to delete files that another application may be "holding" open. Generally, it's tricky to try to delete files from within a running Word instance, no matter what kind of solution. Most developers end up deleting at the start of a new Word session or use a separate application that only runs once Word has quit.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by D.ARUN Sunday, July 17, 2011 2:26 PM
    Thursday, July 7, 2011 1:24 PM
    Moderator

All replies

  • Hi Arun

    Did you create it using the "Shared Add-in" template in Visual Studio or using VSTO?

    What kinds of things does the add-in contain? (Ribbon, Task Pane... that kind of thing)

    Do you have all your code in try...catch blocks?


    Cindy Meister, VSTO/Word MVP
    Tuesday, July 5, 2011 7:19 AM
    Moderator
  • Hi Cindy Meister,

     

    Thank for your reply.

    We are using the template in Visual Studio 2008 to create the Add-In.

    Add-In Contain Ribbon as well as Task Pane.

    Yes all out code is with in the try and catch.

     

    Please let me know if you have any question.

     

    Thanks

     

     


    ARUN
    Tuesday, July 5, 2011 8:29 AM
  • Hi Arun

    It sounds as if you're using VSTO (the template was in an "Office" folder), so I'm going to move your question to the VSTO forum, where you'll find more VSTO technology specialists.

    A few additional follow-up questions

    1. Do you ever see problems when you Debug the Add-in from within Visual Studio? Or is the problem only when it's installed on client machines?

    2. Do you know whether there are other add-ins installed on the client machines that could be conflicting with your add-in?

    3. Are you able to find any pattern when the add-in is becoming disabled? For example, do people use a particular tool in the add-in and then notice it becomes disabled?

    4. Have you built any logging capability into the add-in so that you can track the actions being taken before it becomes disabled?


    Cindy Meister, VSTO/Word MVP
    Tuesday, July 5, 2011 8:37 AM
    Moderator
  • Hi,

    1- As long as I am in my dev machine never saw this problem and again this happen 1 out of 10 time when I install in the client machine.

    2- Yes we do have Outlook and Adobe Add-In on the same machine.

    3- No, we don't see any particular Pattern- but yes we notice this only happen when word get crash in some way.

    4- yes we do have logging capability we are using the log4net for that, but we dont see any thing special in log file that help us on this.

    like this-

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                //long startTime = DateTime.Now.Ticks;

                GlobalObjects.Log4net.Debug("ThisAddIn.ThisAddIn_Startup: Entered function");

                try
                {
                    Globals.ThisAddIn.Application.WindowSelectionChange += new Microsoft.Office.Interop.Word.ApplicationEvents4_WindowSelectionChangeEventHandler(Application_WindowSelectionChange);
                    Globals.ThisAddIn.Application.DocumentBeforeSave += new Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentBeforeSaveEventHandler(Application_DocumentBeforeSave);
                }
                catch (Exception ex)
                {
                    GlobalObjects.Log4net.Error("ThisAddIn.ThisAddIn_Startup: " + ex.Message);
                }
              

            }

     

     void Application_DocumentBeforeSave(Microsoft.Office.Interop.Word.Document Doc, ref bool SaveAsUI, ref bool Cancel)
            {
                GlobalObjects.Log4net.Debug("ThisAddIn.Application_DocumentBeforeSave: Entered function");

                Microsoft.Office.Core.MetaProperties metaProperties = null;

                // try to get the document properties
                try
                {
                    GlobalObjects.Log4net.Debug("ThisAddIn.Application_DocumentBeforeSave: Getting Properties");
                    metaProperties = Globals.ThisAddIn.Application.ActiveDocument.ContentTypeProperties;
                }
                catch (Exception ex)
                {
                    GlobalObjects.Log4net.Error("ThisAddIn.Application_DocumentBeforeSave: " + ex.Message);
                }

                // if get properties worked
                if (metaProperties != null)
                {
                    try
                    {
                        if (Convert.ToBoolean(metaProperties["Finalised"].Value.ToString()))
                        {
                            Cancel = true;
                            MessageBox.Show("This is a Read-Only document.  Unable to save.  Please save as a draft within Profile.");
                        }
                    }
                    catch (Exception ex)
                    {
                        GlobalObjects.Log4net.Error("ThisAddIn.Application_DocumentBeforeSave: " + ex.Message);

                    }
                }
            }

     private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
                GlobalObjects.Log4net.Debug("ThisAddIn.ThisAddIn_Shutdown: Entered function");

                try
                {
                    FileHelper.CleanUpDirectory(FileHelper.TempFolder);
                }
                catch (Exception ex)
                {
                    GlobalObjects.Log4net.Error("ThisAddIn.ThisAddIn_Shutdown: " + ex.Message);
                }
            }

            void Application_WindowSelectionChange(Microsoft.Office.Interop.Word.Selection Sel)
            {
                GlobalObjects.Log4net.Debug("ProfileRibbon.ProfileRibbon: Entered function");

                Microsoft.Office.Core.MetaProperties metaProperties = null;

                // try to get the document properties
                try
                {
                    GlobalObjects.Log4net.Debug("MetadataForm.SavePropertiesToMetadata: Performing Word ActiveDocument.ContentTypeProperties");
                    metaProperties = Globals.ThisAddIn.Application.ActiveDocument.ContentTypeProperties;
                }
                catch (Exception ex)
                {
                    GlobalObjects.Log4net.Error("MetadataForm.SavePropertiesToMetadata: " + ex.Message);
                }

                // if get properties worked
                if (metaProperties != null)
                {
                    try
                    {
                        //get case id
                        string caseId = metaProperties["Case ID"].Value.ToString();
                        Globals.ThisAddIn.Application.DisplayDocumentInformationPanel = false;
                    }
                    catch (Exception ex)
                    {
                        GlobalObjects.Log4net.Error("MetadataForm.SavePropertiesToMetadata: " + ex.Message);
                    }
                }
            }

    Thanks

     


    ARUN
    Tuesday, July 5, 2011 9:04 AM
  • Hi Arun

    OK, I'm not a specialist in this area, but the information you've provided should help in tracking this down. A couple of remarks:

    <<2- Yes we do have Outlook and Adobe Add-In on the same machine.>>

    If the Outlook add-in is running in Outlook, then that shouldn't be causing problems in Word. BUT the Adobe Add-in could be conflicting. If you have a client that wouldn't mind doing some intensive testing, I'd have him UNINSTALL the Adobe tool and see if he can then make Word crash (and thus disable your add-in).

    <<3- No, we don't see any particular Pattern- but yes we notice this only happen when word get crash in some way.>>

    If Word is crashing, then there's definitely some kind of conflict going on, the question is: where and what. Without any kind of pattern or reproducible steps, something like this is very difficult to track down.

    You show me the events your add-in is using and you're right: the conflict could be occurring in the events. For example, if your Add-in and the Adobe add-in are using the same events it's quite possible that, under certain "optimal" circumstances, both add-ins are doing something at the same time and that's causing the crash.

    the other place to look at more closely is ThisAddin_Shutdown. We don't know what FileHelper.CleanUpDirectory is doing, but perhaps that's not finishing before the add-in unloads, thus causing a problem.


    Cindy Meister, VSTO/Word MVP
    Tuesday, July 5, 2011 9:42 AM
    Moderator
  • Hi,

    Here is the code of CleanUpDirectory

    static public void CleanUpDirectory(string directory)
            {
                GlobalObjects.Log4net.Debug("FileHelper.CleanUpDirectory: Entered function");
                GlobalObjects.Log4net.Debug("FileHelper.CleanUpDirectory: Parameter directory = '" + directory + "'");

                try
                {
                    // get all the files in that directory
                    string[] files = Directory.GetFiles(directory);

                    // process each file
                    foreach (string file in files)
                    {
                        try
                        {
                            File.Delete(file);
                        }
                        catch
                        {
                            // swallow the exception and try the next file
                        }
                    }
                }
                catch
                {
                    // swallow the exception
                }

                GlobalObjects.Log4net.Debug("FileHelper.CleanUpDirectory: Return = 'void'");
            }

    Do you feel this is causing any problem?

    Thanks


    ARUN
    Tuesday, July 5, 2011 9:47 AM
  • Hi Arun

    That's very difficult to say at this remove. As I mentioned, all you can do is try various things. Possibly the problem comes from trying to delete files that another application may be "holding" open. Generally, it's tricky to try to delete files from within a running Word instance, no matter what kind of solution. Most developers end up deleting at the start of a new Word session or use a separate application that only runs once Word has quit.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by D.ARUN Sunday, July 17, 2011 2:26 PM
    Thursday, July 7, 2011 1:24 PM
    Moderator