none
.Net Word Addin hanging RRS feed

  • Question

  • Hi all,

     I crate a word addin using shared addin project using Microsoft visual studio 2008.

     I created a sample addin just to place some test in application.selection.range. Here if i just use com object it will work all time as long as I click button to do the operation. But if I just use a system .net object like, get a text from XML Document object and insert that text in range then it just hang after doing it some 10 or 12 times.

    //this work all time if i click button n number of times
    void button_Click(CommandBarButton Ctrl, ref bool CancelDefault)
        {
          Application app = (Application)Ctrl.Application;
          Range r = app.Selection.Range;
          XmlDocument doc = new XmlDocument();
          object missingvalue = Missing.Value;
          try
          {
            Document currentdocument = app.ActiveDocument;
            r.InsertXML("<test>dfadf dfas fsd f sdf sda f da ffa sdf asd fas df sdf asdf sd as df asdf asdf s </test>", ref missingvalue);
          }
          finally
          {
            missingvalue = null;
          }
    
        }
    
    //the same method if i try to get xml from an xmldocument it will work only for some 10 or 11 times then it just stop responding
    void button_Click(CommandBarButton Ctrl, ref bool CancelDefault)
        {
          Application app = (Application)Ctrl.Application;
          Range r = app.Selection.Range;
          XmlDocument doc = new XmlDocument();
          object missingvalue = Missing.Value;
          try
          {
            doc.Load(@"C:\Working\bin\Debug\testing.xml");
            Document currentdocument = app.ActiveDocument;
            r.InsertXML(doc.InnerXml, ref missingvalue);
          }
          finally
          {
            missingvalue = null;
          }
    
        }

    Can any one please help me on this ?

    Is it some thing related with com object management or something ?

     

    Thanks

    Sameer K

    Thursday, March 17, 2011 2:56 PM

Answers

  • Ahh Finally I found the solution.

    Here the commanbuttom I am createing on runtime. And that button is created in a function. Here I need to declare button object in class level. Then it works all the time


    Thanks Sameer Kamarudeen
    Thursday, March 17, 2011 6:23 PM

All replies

  • Ahh Finally I found the solution.

    Here the commanbuttom I am createing on runtime. And that button is created in a function. Here I need to declare button object in class level. Then it works all the time


    Thanks Sameer Kamarudeen
    Thursday, March 17, 2011 6:23 PM
  • Hello Sameer,

    Glad to know that you have found a solution for this issue. Also thanks very much for coming back and sharing this solution with us. Absolutely, it will probably help others facing the same issue in this forum. Have a nice day.


    Bessie Zhao [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.

    Friday, March 18, 2011 6:26 AM