I just ran into something that I have never seen before related to a SoapException:

I was updating my Export JavaScript utility when I received an error message that was blank.  Very odd, I thought.  After a bit of digging, I found the error:

Server was unable to process request.
—> Exception has been thrown by the target of an invocation.
—> The type initializer for 'Microsoft.Crm.WebServices.CrmAuthenticationSoapExtensionBase' threw an exception.
—> The server is not operational.

Now at this point, I really don’t know what happened, but my development CRM 4.0 server was in some type of non-functional state that required me to perform an IISRESET to recover from.  That is not the interesting thing here today.

The interesting thing is where the error message was found.  Here is an example the code that normally use to detect an error when using the CRM Web Service:

catch (SoapException ex)
{
    MessageBox.Show(ex.Detail.InnerText, 
                    Properties.Resources.MSG_AN_ERROR_HAS_OCCURRED, 
                    MessageBoxButtons.OK, 
                    MessageBoxIcon.Error);
}

Usually, the actual error message is found in the SoapException.Detail property and you can access it via the InnerText or InnerXml properties, depending on how you wish to handle it.

Today, the error message was actually in the SoapException.Message property, which I find very odd.  As I said, I’ve never seen this before so I don’t know what happened, but in order to prevent a blank error message from appearing to the user, I created the following work around:

catch (SoapException ex)
{
    string errorMessage = ex.Detail.InnerText;

    if (string.IsNullOrEmpty(errorMessage))
    {
        errorMessage = ex.Message;
    }

    MessageBox.Show(errorMessage, 
                    Properties.Resources.MSG_AN_ERROR_HAS_OCCURRED, 
                    MessageBoxButtons.OK, 
                    MessageBoxIcon.Error);
}

As you can see, I just take into account the possibility that the Detail.InnerText property is blank and if so, just use the standard Message property to be safe.

Trackback

2 comments untill now

  1. [...] Exception handling when working with the CRM Web Services Posted on July 26th, 2010 Mitch Milam Print No comments I just ran into something that I have never seen before related to a SoapException: I was updating my Export JavaScript utility when I received an error message that was blank. Very odd, I thought. After a bit of digging, I found the error: Server was unable to process request. —> Exception has been thrown by the target of an invocation. —> The type initializer for 'Microsoft.Crm.WebServices.CrmAuthenticationSoapExtensionBase' threw an exception. —> The server is not operational. Now at this point, I really don’t know what happened, but my development CRM 4.0 server was in some type of non-functional state that required me to perform an IISRESET to recover from. That is not the interesting thing here today. The interesting thing is where the error message was found. Here is an example the code that normally use to detect an error when using the CRM Web Service: catch (SoapException ex) { MessageBox.Show(ex.Detail.InnerText, Properties.Resources.MSG_AN_ERROR_HAS_OCCURRED, MessageBoxButtons.OK, MessageBoxIcon.Error); }Usually, the actual error message is found in the SoapException.Detail property and you can access it via the InnerText or InnerXml properties, depending on how you wish to handle it. Today, the error message was actually in the SoapException.Message property, which I find very odd. As I said, I’ve never seen this before so I don’t know what happened, but in order to prevent a blank error message from appearing to the user, I created the following work around: catch (SoapException ex) { string errorMessage = ex.Detail.InnerText; if (string.IsNullOrEmpty(errorMessage)) { errorMessage = ex.Message; } MessageBox.Show(errorMessage, Properties.Resources.MSG_AN_ERROR_HAS_OCCURRED, MessageBoxButtons.OK, MessageBoxIcon.Error); }As you can see, I just take into account the possibility that the Detail.InnerText property is blank and if so, just use the standard Message property to be safe. Posted on August 10, 2010 by roman20007 Source [...]

  2. [...] handling when working with the CRM Web Services Posted on August 10, 2010 by roman20007 Source (by Mitch [...]

Add your comment now

Sign up for our new KnowledgeBits service and get news, tips and tricks and more, delivered straight to your inbox.