“System.Runtime.InteropServices.COMException (0x80070102): Operation failed” trying to send a Fax from an ASP.NET application

I recently had a support case where the customer was trying to send a fax from an ASP.NET application but was getting this error when they did:

System.Runtime.InteropServices.COMException (0x80070102): Operation failed

They got this error after a short delay after executing the fax code. They were trying to use FAXCOMEXLib with code similar to the example documented here. You can see from looking around the internet that other people have tried this and run into similar errors. For example this person also hit an InteropServices.COMException as well, albeit with an error code of 0x80070483. 

Errors of the form 0x8007xxxx indicate a Win32 error. A quick way to translate these is to take the last 4 digits, convert to decimal and plug into NET HELPMSG at a command prompt:

>net helpmsg 258
The wait operation timed out.

>net helpmsg 1155
No application is associated with the specified file for this operation.

Turns out the way that faxing works is it uses ShelExecute to launch the document you are trying to fax in whatever application is associated with the file extension for that document. The code initiating the fax waits for that shelled process to complete its job before continuing. In my customer’s case the error was indicating that never completed. In that other case I link to above it looks like no file association could be worked out for the document being faxed.

What you have to remember in this sort of scenario is that the process performing the faxing operation is not running like a normal user. By default it will be running under the NETWORK SERVICE account, although as part of trouble shooting my customer had tried running the application under various combinations of user account.

From looking at some memory dumps after the fax operation had been initiated we could see that the ShellExecute had been called, for a PDF document, and we were blocked waiting for the shelled process to complete – which in this case was Adobe Reader 9.0 (AcroRd32.exe). 

When we investigated with Process Monitor we noticed that AcroRd32.exe was launching correctly but then exiting very rapidly with an exit code of 1, indicating an error had occurred. Closer inspection showed that just prior to exiting it looked for this registry key and didn’t find it:

HKEY_LOCAL_MACHINE.DEFAULTSoftwareAdobeAcrobat Reader9.0AdobeViewer

When I checked the same key (without the .DEFAULT) under my own HKEY_CURRENT_USER hive I could see this key would contain information such as whether the user had accepted the Adobe EULA etc.

The .DEFAULT key under HKLM is the hive that is used for system accounts like SYSTEM and NETWORK SERVICE.

I suggested that the customer configure the application pool to run with a specific local user account and that they actually log on locally with that account one time and run Adobe Reader (and accept any EULAs etc).

After doing that, it all worked.