RPC_E_CALL_CANCELED (0X80010002) - Message filter canceled call
This error pops up when a COM or RPC call gets canceled by the message filter, usually during Outlook or Office automation. It's a timing issue, not a hardware failure.
When you see this error
You're running a script or an Outlook add-in that automates Outlook — maybe sending emails, reading the calendar, or pulling contacts. Then it stops with RPC_E_CALL_CANCELED (0X80010002). The message says the call was canceled by the message filter. This happens most often when you're calling Outlook from an external program — like a VBA macro, a PowerShell script, or a C# app — and Outlook is busy doing something else (syncing, sending, or showing a security prompt).
What causes it
Windows uses COM (Component Object Model) to let programs talk to each other. When Program A calls Program B (like your script calling Outlook), a message filter sits in between. That filter checks if the call should go through. If Program B is in the middle of something else — like showing a dialog box or processing a different COM call — the filter says "no, this call is canceled." The filter doesn't wait. It just kills the call and returns 0X80010002.
This isn't a bug in your code. It's a race condition. Your script sends a COM request at the exact moment Outlook can't accept it. The fix is to make your script handle that timing — either by retrying, by putting Outlook in a state where it's ready, or by disabling the message filter temporarily.
The fix: step by step
Step 1: Add retry logic to your script
The simplest fix is to wrap the failing call in a retry loop. In VBA, that looks like this:
Dim retryCount As Integer
Dim success As Boolean
retryCount = 0
success = False
Do While retryCount < 5 And Not success
On Error Resume Next
' your Outlook call here — for example:
Set olApp = GetObject(, "Outlook.Application")
If Err.Number = 0 Then
success = True
Else
Err.Clear
retryCount = retryCount + 1
Application.Wait (Now + TimeValue("0:00:01")) ' wait 1 second
End If
Loop
On Error GoTo 0
If Not success Then
MsgBox "Could not connect to Outlook after 5 tries."
End If
After running this, you should see either a successful connection or a message box after five tries. The wait gives Outlook time to finish whatever it was doing.
Step 2: Disable Outlook security prompts (if applicable)
Outlook's Object Model Guard often triggers this error. That's the security feature that shows "A program is trying to access email addresses" prompts. Those prompts block your COM call. You can disable the prompts with a registry tweak:
- Close Outlook.
- Open Regedit (Windows key + R, type
regedit, press Enter). - Go to:
HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Security(use 15.0 for Office 2013, 14.0 for 2010). - If the
Securitykey doesn't exist, right-clickOutlook, choose New > Key, name itSecurity. - Right-click in the right pane, choose New > DWORD (32-bit). Name it
DisableObjectModelPrompt. - Set its value to
1. - Click OK, close Regedit.
After doing this, reopen Outlook and run your script again. You won't see the security prompts, and the error should stop.
Step 3: Register a custom message filter (advanced)
If you're writing a C# or C++ app that hosts Outlook, you can register your own message filter that retries the call instead of canceling it. The key interface is IMessageFilter. Here's a C# snippet that does the trick:
public class OutlookMessageFilter : IMessageFilter
{
public int HandleInComingCall(uint dwCallType, IntPtr htaskCaller, uint dwTickCount, IntPtr lpInterfaceInfo)
{
return (int)SERVERCALL.SERVERCALL_ISHANDLED;
}
public int RetryRejectedCall(IntPtr htaskCallee, uint dwTickCount, int dwRejectType)
{
if (dwRejectType == (int)SERVERCALL_REJECTED)
{
return 5000; // Retry after 5 seconds
}
return -1; // Cancel
}
public int MessagePending(IntPtr htaskCallee, uint dwTickCount, uint dwPendingType)
{
return (int)PENDINGMSG.WAITDEFENSIVELY;
}
}
// Register it before calling Outlook:
Thread messageFilterThread = new Thread(() =>
{
IMessageFilter oldFilter = null;
CoRegisterMessageFilter(new OutlookMessageFilter(), out oldFilter);
});
messageFilterThread.Start();
This tells Windows to wait up to 5 seconds before canceling the call. You'll need to add the COM interop imports. After registering this filter, your calls to Outlook should stop getting canceled early.
What to check if it still fails
- Outlook version mismatch. If your script uses Outlook 2019's object model but you have Outlook 365, some calls behave differently. Check the exact version under File > Office Account > About Outlook.
- Another add-in is blocking. Disable all add-ins (File > Options > Add-ins > Go > uncheck all) and test. If the error goes away, re-enable add-ins one by one to find the culprit.
- Windows RPC service isn't running. Press Win + R, type
services.msc, findRemote Procedure Call (RPC), make sure it's running. If it's stopped, right-click and Start. - Outlook is in offline mode. Check the bottom-right corner of the Outlook window. If it shows "Disconnected" or "Working Offline," switch back to online mode (Send/Receive > Work Offline to toggle). Offline mode blocks some COM calls.
Most people fix this with the retry logic in Step 1. The registry tweak in Step 2 is the real fix if security prompts are the trigger. The custom message filter is overkill unless you're building a production app. Start simple, test after each step.
Was this solution helpful?