How to avoid a System.Runtime.InteropServices.COMException?
Solution 1:
Your code (or some code called by you) is making a call to a COM method which is returning an unknown value. If you can find that then you're half way there.
You could try breaking when the exception is thrown. Go to Debug > Exceptions... and use the Find... option to locate System.Runtime.InteropServices.COMException
. Tick the option to break when it's thrown and then debug your application.
Hopefully it will break somewhere meaningful and you'll be able to trace back and find the source of the error.
Solution 2:
I came across System.Runtime.InteropServices.COMException
while opening a project solution. Sometimes user doesn't have enough priveleges to run some COM
Methods. I ran Visual Studio as Administrator and the exception was gone.
Solution 3:
I got this exception while coping a object(variable) Matrix Array into Excel sheet. The solution to this is, Matrix array Index(i,j) must start from (0,0) whereas Excel sheet should start with Matrix Array index (i,j) from (1,1) .
I hope you this concept.