none
comAddin.Object always NULL RRS feed

  • Question

  • HI,

    I want to write unit test project for my WordAddin project. 

     static Application wordApp = null;

                

    [OneTimeSetUp]
            public static void This_AddIn_Initialize()
            { 
                wordApp = new Application();
                wordDocToTest = wordApp.Documents.Open(testDoc);
                COMAddIns comAddins = wordApp.COMAddIns;
                COMAddIn comAddin = comAddins.Item("HP.HPRM.OfficeIntegration.Word");
                wordApp.Visible = true;
                wordcomobj = (WordAddIn)comAddin.Object; 

            }  

    But the comAddin.Object is always retuning null. I am getting value for comAddin. But comAddin.Object is Null always.

    WordAddin Class:--

    namespace HP.HPRM.OfficeIntegration.Word
    {
        internal class WordAddIn : OfficeAddin
        {

            public WordAddIn(Type typeofAddin)
    {
    base.Initialize(typeofAddin);
    }

           public string GetDocumentName()
            {
                return Globals.ThisAddIn.Application.ActiveDocument.Name;
            }

    }

            OfficeAddin.cs:---

    namespace HP.HPRM.OfficeIntegration
    {

    internal abstract class OfficeAddin
    {

     protected static Type m_typeOfAddin=null;

    internal void Initialize(Type typeOfAddin)
    {
    if (typeOfAddin == null)
    {
    throw new ArgumentNullException("typeOfAddin");
    }

    m_typeOfAddin = typeOfAddin;

    }

    }

    }

    Addin.cs:--

     private WordAddIn comAddinObject;
            
            protected override object RequestComAddInAutomationService()
            {
                if (comAddinObject == null)
                {
                    comAddinObject = new WordAddIn(typeof(ThisAddIn));
                }

                return comAddinObject;
            }

    And for wordaddin.cs project "register com interop" is checked.

    Please suggest how to fix this.

    Monday, July 15, 2019 8:57 AM

All replies