Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 189871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:12:32+00:00 2026-05-11T16:12:32+00:00

Has anyone got any suggestions for unit testing a Managed Application Add-In for Office?

  • 0

Has anyone got any suggestions for unit testing a Managed Application Add-In for Office? I’m using NUnit but I had the same issues with MSTest.

The problem is that there is a .NET assembly loaded inside the Office application (in my case, Word) and I need a reference to that instance of the .NET assembly. I can’t just instantiate the object because it wouldn’t then have an instance of Word to do things to.

Now, I can use the Application.COMAddIns(“Name of addin”).Object interface to get a reference, but that gets me a COM object that is returned through the RequestComAddInAutomationService. My solution so far is that for that object to have proxy methods for every method in the real .NET object that I want to test (all set under conditional-compilation so they disappear in the released version).

The COM object (a VB.NET class) actually has a reference to the instance of the real add-in, but I tried just returning that to NUnit and I got a nice p/Invoke error:

System.Runtime.Remoting.RemotingException : This remoting proxy has no channel sink which means either the server has no registered server channels that are listening, or this application has no suitable client channel to talk to the server.
at System.Runtime.Remoting.Proxies.RemotingProxy.InternalInvoke(IMethodCallMessage reqMcmMsg, Boolean useDispatchMessage, Int32 callType)
at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(IMessage reqMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

I tried making the main add-in COM visible and the error changes:

System.InvalidOperationException : Operation is not valid due to the current state of the object.
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)

While I have a work-around, it’s messy and puts lots of test code in the real project instead of the test project – which isn’t really the way NUnit is meant to work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:12:32+00:00Added an answer on May 11, 2026 at 4:12 pm

    This is how I resolved it.

    1. Just about everything in my add-in runs from the Click method of a button in the UI. I have changed all those Click methods to consist only of a simple, parameterless call.

    2. I then created a new file (Partial Class) called EntryPoint that had lots of very short Friend Subs, each of which was usually one or two calls to parameterised worker functions, so that all the Click methods just called into this file. So, for example, there’s a function that opens a standard document and calls a “save as” into our DMS. The function takes a parameter of which document to open, and there are a couple of dozen standard documents that we use.

    So I have

    Private Sub btnMemo_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean) Handles btnMemo.Click
        DocMemo()
    End Sub
    

    in the ThisAddin and then

    Friend Sub DocMemo()
        OpenDocByNumber("Prec", 8862, 1)
    End Sub
    

    in my new EntryPoints file.

    1. I add a new AddInUtilities file which has

      Public Interface IAddInUtilities

    #If DEBUG Then

    Sub DocMemo()
    

    #End If

    End Interface
    
    
    Public Class AddInUtilities
        Implements IAddInUtilities
        Private Addin as ThisAddIn
    

    #If DEBUG Then

    Public Sub DocMemo() Implements IAddInUtilities.DocMemo
        Addin.DocMemo()
    End Sub
    

    #End If

     Friend Sub New(ByRef theAddin as ThisAddIn)
         Addin=theAddin
     End Sub
     End Class
    
    1. I go to the ThisAddIn file and add in

      Private utilities As AddInUtilities

      Protected Overrides Function RequestComAddInAutomationService() As Object
      If utilities Is Nothing Then
      utilities = New AddInUtilities(Me)
      End If
      Return utilities
      End Function

    And now it’s possible to test the DocMemo() function in EntryPoints using NUnit, something like this:

    <TestFixture()> Public Class Numbering
    
    Private appWord As Word.Application
    Private objMacros As Object
    
    <TestFixtureSetUp()> Public Sub LaunchWord()
        appWord = New Word.Application
        appWord.Visible = True
    
        Dim AddIn As COMAddIn = Nothing
        Dim AddInUtilities As IAddInUtilities
        For Each tempAddin As COMAddIn In appWord.COMAddIns
            If tempAddin.Description = "CobbettsMacrosVsto" Then
                AddIn = tempAddin
            End If
        Next
        AddInUtilities = AddIn.Object
        objMacros = AddInUtilities.TestObject
    
    
    End Sub
    
    <Test()> Public Sub DocMemo()
    
    
        objMacros.DocMemo()
    End Sub
    
    <TestFixtureTearDown()> Public Sub TearDown()
        appWord.Quit(False)
    End Sub
    
    End Class
    

    The only thing you can’t then unit test are the actual Click events, because you’re calling into EntryPoints in a different way, ie through the RequestComAddInAutomationService interface rather than through the event handlers.

    But it works!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 120k
  • Answers 120k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would recommend the following mapping: "/rest/url/$id?"(resource:"urlRest") Below is the… May 12, 2026 at 12:13 am
  • Editorial Team
    Editorial Team added an answer The extra "d" parameter is added by the .NET framework… May 12, 2026 at 12:13 am
  • Editorial Team
    Editorial Team added an answer Add an onmouseover function handler to the element that is… May 12, 2026 at 12:13 am

Related Questions

This is a difficult and open-ended question I know, but I thought I'd throw
We need to add a wiki to an already existing website, however we want
I'd like to learn how to program in Assembler. I've done a bit of
As the question implies, I'm looking for a way to programmatically screen grab a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.