Export (0) Print
Expand All

PSClientError class

Contains information about a SOAP exception for a PSI method.

System.Object
  Microsoft.Office.Project.Server.Library.PSClientError

Namespace:  Microsoft.Office.Project.Server.Library
Assembly:  Microsoft.Office.Project.Server.Library (in Microsoft.Office.Project.Server.Library.dll)

[SerializableAttribute]
public class PSClientError : ISerializable

To get a list of all errors that occur if you get an exception when you call a PSI method, pass the SoapException object to the Microsoft.Office.Project.Server.Library.PSClientError class constructor. You can then use GetAllErrors to store the error information in a PSErrorInfo array and enumerate the errors, as in the following example.

NoteNote

The PSErrorInfo object may not include all of the information you need. For example, if you use Resource.CheckOutResources where some of the resources are already checked out, PSErrorInfo shows the reason for failure for each resource that cannot be checked out, but does not include the resource name or GUID. For a way to get more information, see CheckOutResources.

using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Services.Protocols;
using System.Windows.Forms;
using PSLibrary = Microsoft.Office.Project.Server.Library;
. . .
try
{
    /* call a PSI method */
}
catch (SoapException ex)
{
    string errAttributeName;
    string errAttribute;
    string errMess = "".PadRight(30, '=') + "\r\n" + "Error: " + "\r\n";

    PSLibrary.PSClientError error = new PSLibrary.PSClientError(ex);
    PSLibrary.PSErrorInfo[] errors = error.GetAllErrors();
    PSLibrary.PSErrorInfo thisError;

    for (int i = 0; i < errors.Length; i++)
    {
        thisError = errors[i];
        errMess += "\n" + ex.Message.ToString() + "\r\n";
        errMess += "".PadRight(30, '=') + "\r\nPSCLientError Output:\r\n \r\n";
        errMess += thisError.ErrId.ToString() + "\n";

        for (int j = 0; j < thisError.ErrorAttributes.Length; j++)
        {
            errAttributeName = thisError.ErrorAttributeNames()[j];
            errAttribute = thisError.ErrorAttributes[j];
            errMess += "\r\n\t" + errAttributeName +
                       ": " + errAttribute;
        }
        errMess += "\r\n".PadRight(30, '=');
    }
    MessageBox.Show(errMess, "Error", MessageBoxButtons.OK,
        MessageBoxIcon.Error);
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft