We help IT Professionals succeed at work.

Debugging COM Interop HResult codes (VSTO)

I have an Excel add-in firing an HRESULT 0x800401A8 error, when calling the getter of Worksheet.Parent.

I would be glad if anyone could let me know what the error might be, but more importantly and more generally, I would like to know how I can understand these HResult codes?

I did the following but am still confused:

Read the Microsoft's documentation on the Structure of COM error Codes.
Checked this SO thread.
Tried my chances with Magnum DB.

Thanks!
Comment
Watch Question

John TsioumprisSoftware & Systems Engineer
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Ama OlvFull stack Developer

Author

Commented:
Yes I did. No dual instances of Excel in my case. The error came up after a new release, and only one client is having problems (so far two users of this client are affected). Any idea what the HResult code means in that case?
John TsioumprisSoftware & Systems Engineer
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
John TsioumprisSoftware & Systems Engineer
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Can you give some more info on the code and what it does.
Searching on Google reveals that are a number of possible causes..someone proceeded to  uninstalling reinstalling Office to get this resolved...
Have you checked these 2 users if Excel has some other issues...like problem with VBE...some extra/missing addins...other issues.
Ama OlvFull stack Developer

Author

Commented:
The code is meant to insert a given worksheet after the active worksheet. To do that, I have a Template.xls file stored as a Byte() resource in my .Net project. The resource is copied to a temporary file, opened by the instance of Excel from which the add-in is executed, then the wanted sheet is copied, then pasted after the active worksheet.

I have a custom function which wraps the native worksheet.copy function. My function requires an Excel.Worksheet to be provided (the sheet after which the new sheet should be copied). To retrieve the workbook the new sheet should be copied to, I do

Dim DestinationWorkbook as Excel.Workbook = After.Parent

Open in new window


I have used this wrapper for nearly a year now; it never triggered any errors. I suspect the workbook the client is working on might be special. Maybe it has broken chart sheets, pivot charts, etc. I have a meeting with them in an hour. I would like to gather as much info as possible before this "emergency" meeting. How do you usually troubleshoot the HResult errors? Do you just google the code?

The users cleaned, then ended up re-installing Office 365, and re-installing the add-in.
John TsioumprisSoftware & Systems Engineer
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
The whole uninstall/install is a bit suspicious...maybe it didn't got cleaned properly...
Also there is a good chance that problematic registry keys are in existance...usually these hold the "key to paradise"....a permission missing and eveything bombs out.
Ama OlvFull stack Developer

Author

Commented:
Permissions are also under suspicion. The update included a feature to manually update the add-in (via click once).
This is nearly a copy/paste of the code provided by Microsoft here: https://docs.microsoft.com/en-us/visualstudio/deployment/how-to-check-for-application-updates-programmatically-using-the-clickonce-deployment-api?view=vs-2019

Although the add-in is able to successfully check for available updates, it cannot then apply the update: Trust Not Granted Exception. I guess Excel wraps the add-in in a virtual environment which rejects the elevation of rights. Do you believe including source code which references the ClickOnce API might involve the new release to require more trust than was originally granted, hence causing all sorts of problems?
John TsioumprisSoftware & Systems Engineer
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
This is something i have never worked with...
Full stack Developer
Commented:
The issue was that when Excel starts and generates a blank workbook, this workbook is automatically closed if it is left untouched and another workbook is opened: the add-in would open the Tempalte.xls file, which would lead Excel to close the blank Workbook, which is why then calling the .Parent property of the blank sheet would trigger an error.