Use DCOM to convert docx to pdf gets System.Runtime.InteropServices.COMException (0x8000401A)

0

I have console program which uses DCOM to manipulate docx files on network (i.e. \\192.168.1.4\data) and then save to the same network place as pdf. It does this in a batch, so every time run it, it process about 10 files in a loop.

If I run the exe manually, everything works fine. But then I setup a Task scheduler which runs it every 30 minutues. The account to run it is my account. It runs ok for some hours, then suddenly, get this Exception for every conversion.

System.Runtime.InteropServices.COMException (0x8000401A): Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 8000401a The server process could not be started because the configured identity is incorrect. Check the username and password. (Exception from HRESULT: 0x8000401A).
at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType)
at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj)
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)

The DCOM config for WORD is set as Interactive User. I also set it as my account, get this excption:

System.Runtime.InteropServices.COMException (0x800A1420): This is not a valid file name.
Try one or more of the following:
* Check the path to make sure it was typed correctly.
* Select a file from the list of files and folders.
   at Microsoft.Office.Interop.Word.InlineShapes.AddPicture(String FileName, Object& LinkToFile, Object& SaveWithDocument, Object& Range)

In the code, it uses AddPicture to add an image on the network to the docx. And the network path is valid, not sure why has this exception, but I guess it is because of the DCOM config.

If set DCOM config for WORD as launching user, it has the first exception (above) from the beginning, the conversion never succeeded.

The code is similar to:

var wordApp = new Word.Application();
var adoc = new Word.Document();
try
{
    wordApp.Visible = false;
    adoc = wordApp.Documents.Open(ref fileNameDocx,
        ref missing, ref missing, ref missing, ref missing,
        ref missing, ref missing, ref missing, ref missing,
        ref missing, ref missing, ref missing, ref missing,
        ref missing, ref missing, ref missing);

    adoc.Activate();    // ***
    ......
}
finally
{
    _log.Info("Releasing Object ...");
    ReleaseObject(adoc);
    ReleaseObject(wordApp);
    _log.Info("Releasing Object: Done.");
}                   

The exception happens at the line adoc.Activate();

Anyone knows how to solve this problem?

Thanks

  • I'm still having this issue. However, I noticed that when this happened, if the program pause some time, say 1 hour, then try the same file again, it works again. This kind of solved the issue for now, but it still be interesting to know why/how to fix this.
c#
.net
asked on Stack Overflow Aug 7, 2020 by urlreader • edited Aug 11, 2020 by urlreader

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0