Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
587 views
in Technique[技术] by (71.8m points)

c# Interop Word "Call was rejected by callee" only when dialogue is open

I have a simple c# application, (which helps entering Header/Footer.)

So all works fine, but when any Dialogue (eg. Select Font) in Word ist opened, I can't connect the "ActiveDocument.Name" any more.

private IopW.Application wordApp;
private IopW.Document wordDoc;
...
wordDoc = wordApp.Documents.Open(Datei);
...
try 
{
    if (wordApp != null && wordApp.ActiveDocument != null)
    {
        Console.Write(wordApp.ActiveDocument.name);
             // Works fine, **if no Dialog is opened** in Word.
             // but when any Dialog is opened i get the error: 
             // System.Runtime.InteropServices.COMException: 
             //     "Aufruf wurde durch Aufgerufenen abgelehnt. 
             //     (Ausnahme von HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))"
             // In English: "Call was rejected by callee"
    }
} catch
{
    ...
}

Try/catch does not prevent the error beeing printed.

Remember: wordApp.ActiveDocument != null, but wordApp.ActiveDocument.name is rejected.

So:

  • How can I prevent this error,
  • or determine if any Dialogue is open,
  • or determine, if my next request will rejected.
question from:https://stackoverflow.com/questions/65849537/c-sharp-interop-word-call-was-rejected-by-callee-only-when-dialogue-is-open

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...