I have been trying to load an excel file using the following code -
_workbook = await Task.Run(() =>
{
return _excelApp.Workbooks.Open(fileName);
}).ConfigureAwait(false);
If I provide a non-existent file name in the fileName
parameter, it's throwing a generic COMException with the following error code - 0x800a03ec
According to the Interop documentation, the .NET runtime should convert the HResult to a specific exception - https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.comexception?view=net-5.0
For this specific case, I was expecting to get a FileNotFoundException
instead of the generic COMException
. But since the HResult is not FILE_NOT_FOUND
, its throwing the generic COMException
. My question is why the interop is returning a wrong HResult? Is there anything wrong I have done here or its a bug in Excel.Interop?