Visual Basic > Visual Basic Forums > Visual Basic Interop and Upgrade > RPC_E_CALL_REJECTED during Word automation from VB2005 when copying in Paint...
Ask a questionAsk a question
 

QuestionRPC_E_CALL_REJECTED during Word automation from VB2005 when copying in Paint...

  • Friday, December 15, 2006 12:57 PMSaskia Brand Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi all,

    I have a problem involving Word automation and the use of Paint.

    The situation is:
    A Word-document is being manipulated through automation. When I open Paint and copy (part of) the picture, I get a 'call was rejected by callee' error from the VB2005 application automating Word.

    When I use sleep(100) and retry (resume) the statement, it works fine. However, as long as the Paint session is open, every action I perform on Word will require a second try. Since there's quite a lot of them, this will slow the application down considerably. As soon as Paint is closed, the Word-automation continues without errors.

    Interesting detail: this application was upgraded from VB6, with only minimal changes. This problem did not occur in VB6.

    Does anyone have any idea what causes this and/or how this can be solved?
    (Apart from forcing users to close Paint or use some other program for getting their screen captures, that is...)

    Technical details:
    Using XP SP2, Word 2003 SP2 and VS2005 Pro.

    Thanks in advance,
    Saskia Brand

All Replies

  • Thursday, December 21, 2006 9:28 PMJeff Tindall Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    You are not alone.  I was able to replicate the issue, but don't have a good resolution (other than don't have MS Paint open).  In my scenario, the environment is:

    .NET 2.0 - C#
    Word 2003
    Windows XP Pro

    I don't recall having this issue on the 1.1 Framework (but I have not verified yet).

    Good luck, I hope someone can come up with a why...
    ~Jeff
  • Wednesday, December 27, 2006 10:42 PMMSFT Abel ValadezModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Is your application marked as STA or is not marked at all? If so, try to change it to be an MTA and try it again.

    http://msdn2.microsoft.com/en-us/library/system.mtathreadattribute.aspx

    Hope this helps,

  • Thursday, December 28, 2006 9:20 PMSaskia Brand Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I tried this on my test-app (I've been able to reproduce the problem at home) and unfortunately it didn't help much. The error changed from RPC_E_CALL_REJECTED to RPC_E_SERVERCALL_RETRYLATER, but that's it.

    FYI, here's how I've reproduced this at home. Take a form (Form1) with a button (Button1) and paste the following code:

    Public Class Form1
        Dim mwrdapp As Word.Application
        Dim blnContinue As Boolean = False

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            mwrdapp = New Word.Application
            mwrdapp.Documents.Add()
            mwrdapp.Visible = True
        End Sub

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Do
                Try
                    mwrdapp.ActiveDocument.Range.Text &= "test copying in Paint" & vbCrLf
                    mwrdapp.ActiveDocument.SaveAs("c:\test.doc")
                Catch ex As Exception
                    MessageBox.Show(ex.ToString)
                End Try
            Loop
        End Sub
    End Class

    Run the app and click button1. You'll see "
    test copying in Paint" being written to Word continuously. Now, open Paint, select an area of the canvas and copy it. Instant error...

  • Thursday, December 28, 2006 11:40 PMMSFT Abel ValadezModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Does this only happen while debugging or does it happen if you run your application outside of the debugger too?

     

  • Friday, December 29, 2006 3:16 PMSaskia Brand Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    We actually found out through users saying the application 'kept crashing'. When we went to the user and looked at what they were doing we noticed the connection to Paint. So, this happens while debugging as wel as in the published application.
  • Friday, January 05, 2007 4:45 AMMSFT Abel ValadezModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    If this also happens when running the application outside of the debugging environment, then it is a problem with either Word or Paint not responding to messages. Unfortunately, I am unable to help in this instance.

     

  • Thursday, October 29, 2009 8:37 AMThomas Lund Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Got the same thing, but noticed another thing that seems to do the trick at my pc. I can have paint open, but once I mark an area of the picture and copy it to the clipboard, the application fails. Just tried it and it can be replicated.

    And yes it does happen outside the development environment

    Sorry not very helpfull, but I am very keen to have this solved too.

    Running
    Vista
    Visual studio 2008
    Office 2007

    Thomas