Type mismatch Exception

Add-in Express™ Support Service
That's what is more important than anything else

Type mismatch Exception
 
briannesbitt


Guest


With one particular client computer we are seeing a "System.Runtime.InteropServices.COMException (0x80020005): Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))" occur from our add-in. The add-in is in PowerPoint but the exception is coming from trying to open an Excel file and read some values. More specifically we are seeing it in 2 places.

1) We open a file using the "_excelApp.Workbooks.Open(file);" method. Then we check to see if Excel is ready. We do this with the following code:


public bool IsReady
{
     get { return _excelApp.ActiveSheet != null && _excelApp.Selection != null; }
}


_excelApp is the Microsoft.Office.Interop.Excel.Application instance.
The _excelApp.ActiveSheet is fine but the exception occurs on the "_excelApp.Selection".

2) The second location we have seen it happen is when we are trying to add a new blank workbook


_excelApp.Workbooks.Add(Missing.Value)


We haven't seen this on any other instances. Any idea as to what seems to be going on?
Posted 29 Sep, 2016 13:30:26 Top
briannesbitt


Guest


Just some additional information. We were able to do a remote session with the client and realized they had other Excel add-ins enabled. We disabled them all and everything worked as expected.

We are hopefully going to be getting the offending add-in as they work through the process of elimination :-)

Any ideas on how to work around this?

Is it possible to disable add-ins when launching Excel via automation?
Posted 29 Sep, 2016 15:41:17 Top
Andrei Smolin


Add-in Express team


Posts: 18823
Joined: 2006-05-11
Hello Brian,

I assume all the Excel add-ins you mentioned are in fact COM add-ins. If so, to turn a COM add-in on or off, you can scan the ExcelApp.COMAddins collection and set Office.COMAddin.Connect=false for each of them. Use the COMAddin.ProgID property to identify your COM add-in.

If however you talk about Excel add-ins, then they won't load if you start Excel programmatically. This is by Excel design. Quite a strange choice.


Andrei Smolin
Add-in Express Team Leader
Posted 30 Sep, 2016 04:46:43 Top
briannesbitt


Guest


So it won't load Excel add-ins when started programmatically. So that means it must be a COM add-in then?

We'll try disabling those as you suggested above setting their Connect property to false. I assume its effective for just that instance and on their next run they will be loaded again?

Also waiting to hear back to see which was the conflict.

Thanks.
Posted 30 Sep, 2016 09:20:13 Top
briannesbitt


Guest


A quick test locally and it seems you get "System.Runtime.InteropServices.COMException (0x80004005): This add-in is installed for all users on this computer and can only be connected or disconnected by an administrator." exceptions depending on how the add-ins were installed.

Seems setting Connect to false isn't really an option?
Posted 30 Sep, 2016 09:26:35 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hello Brian,

I can suggest another solution. You can try to "disable" the add-in via the Windows Registry by modifying the following registry key:
HKCU\Software\Microsoft\Office\Excel\Addins\<AFFECTED-ADD-IN-PROG-ID>\

Try to set the LoadBehavior property to 0 (zero) before creating an Excel instance and restore the value after closing the instance.
Posted 30 Sep, 2016 09:59:40 Top