Exception from HRESULT: 0x800401A8 using ExcelDNA.Testing

172 views
Skip to first unread message

Noor Knowledge TV

unread,
Apr 22, 2022, 12:02:49 PM4/22/22
to Excel-DNA
Hi,

I have developed a excel plugin using ExcelDna and it is working perfectly. Now, I'm writing integration test for my plugin. I'm using the built-in excel template for my test. What I am doing is to load the excel sheet using:

[ExcelFact(Workbook = "Plugin testing.xlsm")]

Then, I invoke the methods that read the data from excel sheet. The same code runs fine if executed from plugin but in testing it throws an error HRESULT: 0x800401A8 using ExcelDNA.Testing.

What I noticed I have different Task.Run where I access excel objects. I need to do this because I need to show progress on real plugin but in testing it throws error. What I am doing wrong?

Regards,
Noor

Govert van Drimmelen

unread,
Apr 25, 2022, 5:13:23 AM4/25/22
to exce...@googlegroups.com

Hi Noor,

 

You should try to always do the COM interop with Excel from the main thread.

Otherwise there are various things that can go wrong – for example Excel is sometimes in a mode where most COM calls are directly rejected.

If you are triggering some COM interop work from another thread (like a ThreadPool thread running a Task) you need to find a way to schedule the COM interop work on the main thread.

In some cases (and inside the add-in) you can call ExcelAsyncUtil.QueueAsMacro to do this.

I’m a bit unsure of whether this would work in a test context, but you can try.

 

-Govert

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/c4d6e15d-02f5-4bce-91b5-7783facdfedbn%40googlegroups.com.

Umer Waheed

unread,
Apr 25, 2022, 8:57:06 AM4/25/22
to Excel-DNA
Hi,

I got the same issue but in my case it happens in static method. It runs fine when using plugin but failed when run from unit tests. I'm also using Task.Run to show progress on UI.

Regards,
Umer Waheed
Reply all
Reply to author
Forward
0 new messages