Backtrack:  
 
by lunarg on September 3rd 2015, at 10:48

When running Blackberry Enterprise Server (BES) 5.0.4 in an environment with users whose mailboxes are located on Exchange 2013 servers, you may encounter the following problem: certain, but not all users lose their connectivity on their mobile devices. They can no longer send or receive e-mail, calendar, contacts.

When looking at the event viewer, an application crash is logged:

Event 1000 Application Error
Faulting application name: BlackBerryAgent.exe, version: 5.0.4.17, time stamp: 0x502e604b
Faulting module name: exmapi32.dll, version: 6.5.8320.0, time stamp: 0x517e1c40
Exception code: 0xc0000005
Fault offset: 0x00010188
Faulting process id: 0x1fbc
Faulting application start time: 0x01d0e0c7a8fec15c
Faulting application path: C:\Program Files (x86)\Research In Motion\BlackBerry Enterprise Server\BlackBerryAgent.exe
Faulting module path: C:\Program Files (x86)\ExchangeMapi\exmapi32.dll
Report Id: f035a5ab-4cba-11e5-9402-0050568c61f0
Faulting package full name:
Faulting package-relative application ID:

Additionally, the BES Controller log shows lines similar to:

BES01_CTRL_01_20150827_0009.log
[30000] (08/27 13:45:53.473):{0x19DC} 'BES01' agent 1 stopped. Exit code = 255
[30000] (08/27 13:45:53.520):{0x19DC} 'BES01' agent 1 started as process 6412
[30000] (08/27 13:45:54.097):{0x19DC} 'BES01' agent 1: UDP log port is 4085
[30000] (08/27 13:45:55.548):{0x19DC} Agent 1: CPU usage 9.960552%
[30000] (08/27 13:46:11.912):{0x19DC} 'BES01' agent 1 stopped. Exit code = 255

(possible) Cause

The issue is caused by a combination of an older version of BES 5.0.4, Exchange 2013 and certain contents of a user's mailbox. In this case, the agent crashes each time a certain item is accessed from the user's mailbox. This causes the agent to restart, and fail again on the same item.

Resolution

The only solution is to install a patch to resolve the issue.

If you have a paid support contract with Research In Motion, then you can obtain the patch through their support channels, but if you are running BES Express, then you do not have that luxury. As the patch is not freely available for download, I've attached it to this post.

Patch instructions

The patch is not an installation EXE but rather a ZIP containing the files that need to be replaced inside the BES installation folder.

Version check recommended!
Before applying the patch, verify the version of BlackberryAgent.exe. If it is lower than 5.0.4.31, the patch can be applied. If the version is the same or higher, then the problems you have are not related to the version of the agent.
  1. Log on to the BES server.
    Start Services (services.msc), and stop all Blackberry related services.
  2. Unpack the patch and copy the files to the installation folder of BES (by default: %PROGRAMFILES%\Research In Motion\BlackBerry Enterprise Server).
    You should be prompted to replace the files. If not, then you are probably not in the right location.
  3. When the files have been replaced, you need to manually register the new version of EWS.dll with .NET Framework.
    Open an elevated command prompt, navigate to the installation location of BES (by default: %PROGRAMFILES%\Research In Motion\BlackBerry Enterprise Server):
    cd "\<path to Blackberry Enterprise Server directory>"
    Run these commands in order:
    "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe" /tlb EWS.dll"
    
    CalHelperWS.exe /regserver
    All commands should complete succesfully (i.e. without errors).
  4. Reboot the server or restart all BES services (whichever you prefer).
  5. After rebooting or restarting all BES services, check the logs again. The agent(s) should no longer crash, and connectivity for the affected users should be restored.