Freigeben über


“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.

HTH

Doug

Comments

  • Anonymous
    August 30, 2011
    The comment has been removed

  • Anonymous
    August 31, 2011
    Just to clarify, the customer was not explicitly doing a ShellExecute. This arose as part of the operation of the Fax API. I think the Fax API is intended for use from desktop applications rather than non-interactive multi-threaded server side applications like ASP.NET.  So to makes this operate correctly there are additional considerations to make. HTH Doug

  • Anonymous
    January 25, 2012
    I believe I am having a similar issue when running my console in Task Scheduler.  It works when the user associated to the task is logged in.  When the user is not logged in to the machine (Vista 64 bit), the operation failes.  Any thoughts Doug?

  • Anonymous
    January 26, 2012
    The comment has been removed

  • Anonymous
    September 13, 2013
    I have the same issue. Adding regirsty keys don't help me. Application works normally but when i start it like windows service i have this error System.Runtime.InteropServices.COMException (0x80070102): Operation failed.   в FAXCOMEXLib.FaxDocumentClass.IFaxDocument_ConnectedSubmit(IFaxServer pFaxServer)   в DTS.FaxSvc.AddDocToQueue(String sDocName, String sDestAddr, String sDocFile, String& sError) в E:SimmsProjProjectsDocTransSvrFaxSvc.cs:строка 232 My code:        public string[] AddDocToQueue(string sDocName, string[] aDestAddr, string sDocFile,            out string sError)        {            sError = null;            IFaxDocument FaxDoc = new FaxDocumentClass(); // Create FaxDocument and set properties            FaxDoc.DocumentName = sDocName;            for(int i=0; i<aDestAddr.Length; ++i)                FaxDoc.Recipients.Add(aDestAddr[i], String.Empty);            FaxDoc.Body = sDocFile;            string[] aFaxJobIDs = null;            try            { // Submit FaxDocument                aFaxJobIDs = (string[])FaxDoc.ConnectedSubmit(FaxSvr);                if(null != aFaxJobIDs)                {                    lock(JobCache)                    {                        //AddJobsToCache(aFaxJobIDs, (int)FAX_JOB_STATUS_ENUM.fjsPENDING, FaxSvcJobHex);                        foreach (string jobID in aFaxJobIDs)                        {                            AddJobsToCache(new FaxJob(jobID, new StatusInfo((int)FAX_JOB_STATUS_ENUM.fjsPENDING, 0, 0)), FaxSvcJobHex);                            }                    }                    int iJobCntDelta = aDestAddr.Length - aFaxJobIDs.Length;                    if(0 < iJobCntDelta) // Resize array of jobs to accord with number of recipients                        Array.Resize<string>(ref aFaxJobIDs, aFaxJobIDs.Length + iJobCntDelta);                }            }            catch(Exception E)            {                sError = E.ToString();            }            return aFaxJobIDs;        }

  • Anonymous
    September 15, 2013
    Hello Grishe4ka The registry key referenced above was just what gave me the clue to the solution. The important thing, if it is a similar problem, is to actually do at least one interactive login as the user account that the service is set to run as.  The 0x80070102 error means "the wait operation timed out". So something is blocked.  Chances are it is a dialogue (invisible) involved in the fax software you are using. Regards Doug

  • Anonymous
    August 26, 2014
    Writing to update this blog in case helps with newer products from Adobe.   For newer Adobe  (v10 or v11), trying to FAX .PDF content from a service will fail now due to additional dialogs being shown from Adobe.   For newer Adobe releases, there is a post in Adobe forums too (forums.adobe.com/.../4277588) on the Adobe protected mode feature that can be set in registry to off   (bProtectedMode:   forums.adobe.com/.../4917697) Other option would be to FAX .PDF content from same interactive session as user or to change the .PDF associated program to something else that works from a service without showing a user interface dialog.

  • Anonymous
    August 26, 2014
    Thanks for sharing Nathan!