An error message cannot be displayed because an optional resource assembly containing it cannot be found

Issue:  So you have a couple of Windows Mobile 5 based prod devices running a .NET Compact Framework 2.0 sp2 application ocasionally getting an error when calling a web service over SSL.  Your trusty logging logs a message along the following lines:

System.Net.WebException: An error message cannot be displayed because an optional resource assembly containing it cannot be found —> System.Net.WebException: An error message cannot be displayed because an optional resource assembly containing it cannot be found

at System.Net.SslConnectionState.PerformClientHandShake()

at System.Net.Connection.connect()

at WorkItem.doWork()

at System.Threading.Timer.ring()

Solution: So whats going on ?… well from the stackdump we can clearly see that the issue is occuring when trying to do a handshake with the remote server “System.Net.SslConnectionState.PerformClientHandShake()”  likely something to do with the cert.  So before jumping to conclusions lets see if we can get a proper error message.

The optional string resource assembly is optional to reduce the footprint of .NET Compact Framework.  To get a more useful error message out of the device the appropriate cab must be installed.  The cab to install in this instance is System_SR_ENU.cab, you can find it in C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE\Diagnostics.  (Note: use System_SR_ENU_wm.cab for Windows Mobile 6.0 based devices).

After installing the cab and re-running the application a more detailed error message is displayed and indicates that the client can’t validate the SSL certificate from the remote server.  Checking the server certificate it appears to be valid and still within 2008 to 2011.  Checking the device shows that the local date time of the device has reverted back to 2005 – one of the end users must have let the backup battery go flat.   Updating the date and time back to present 2010 and hey presto issue resolved :)

hope this helps