Unit testing Excel addin using VSTO


I've been trying to test my addin without success, and even after looking at various sources like MSDN and StackOverflow

I can't seem to be able to do it. Here's my current code (I trimmed to only have the relevant parts)


[assembly: ComVisible(true)]
[assembly: InternalsVisibleTo("MyAddInTest")]


private AddinHelper _comAddinObject;
protected override object RequestComAddInAutomationService()
    return _comAddinObject ?? (_comAddinObject = new AddinHelper());


public interface IAddinHelper
    string GetString();

public class AddinHelper : StandardOleMarshalObject, IAddinHelper
    public string GetString()
        return Globals.ThisAddIn.Application.ActiveWorkbook.Name;


Application = new Application();
Workbook = Application.Workbooks.Add();
COMAddIns comAddins = Application.COMAddIns;
COMAddIn comAddin = comAddins.Item("MyAddIn");
IAddinHelper comObject = (IAddinHelper) comAddin.Object;

The main project references the .NET Assembly version of Microsoft.Office.Interop.Excel with Embed Interop Types set to true. My test project references my VSTO project, and the COM (ActiveX) version of the Interop.

The exception I get is:

Unable to cast COM object of type 'System.__ComObject' to interface type 'MyAddIn.IAddinHelper'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{B523844E-1A41-4118-A0F0-FDFA7BCD77C9}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

I currently use Office 2013 (so Office 15.0) and the references are all pointing to that version, .NET 4.5.3 and Visual Stuio Community 2017. The SO link that I provided seems to be the exact same issue, however I still have the exception when running my tests unlike there.


0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0