Generic handle error method

Here is a generic handle error method I put in my catches.  It will send an email with the inner exception unless it’s null then you get the exception message.  The stack trace is included.

You should the subject from “Application Name” to whatever your application is.
Also you should check out a previous post about a generic send mail method since this method calls that one.

private static void HandleError(Exception ex)
        {
            String errorMessage = String.Empty;

            if (ex.InnerException != null)
            {
                errorMessage = ex.InnerException.ToString();
            }
            else
            {
                errorMessage = ex.Message.ToString();
            }

            var trace = new System.Diagnostics.StackTrace(ex);

            StringBuilder errorBodyString = new StringBuilder();

            errorBodyString = errorBodyString.Append("Exception:" + errorMessage);
            errorBodyString = errorBodyString.Append("<br />");
            errorBodyString = errorBodyString.Append(trace);

String Subject = "Application Name";
            String Body = errorMessage;

           // sendNotification(Subject, errorBodyString.ToString());
        
[tweetmeme only_single=”false”]
Advertisements

Convert Generic List to Array

Here is a method to convert a generic list to an Array.

public static T[] ConvertListToArray<T>(List<T> theList)
{
try
{
if (theList == null)
{
return null;
}

T[] theArray = new T[theList.Count];

for (int i = 0; i < theArray.Length; i++)
{
theArray[i] = theList[i];
}

return theArray;
}
catch (Exception ex)
{
throw ;
}
}

Convert an Array to a generic list

Sometimes you have an array, but a generic list would make better sense.
Here is a method to convert from an array to a generic list.

This comes in handy if you you get an array back a web service (since they can’t return a generic list).

public static List<T> ConvertArrayToList<T>(T[] theArray)
{
try
{
if (theArray == null)
{
return null;
}

List<T> theList = new List<T>();

for (int i = 0; i < theArray.Length; i++)
{
theList.Add(theArray[i]);
}

return theList;
}
catch (Exception ex)
{
throw ;
}
}

SharePoint error in Event Log

If you notice the following error in the event, there is a simple fix.

The Execute method of job definition Microsoft.Office.Server.Administration.ApplicationServerAdministrationServiceJob (ID c7f87cbb-e67d-44a2-9061-5321094aa81e) threw an exception. More information is included below.

 

Open Com Services and check the permissions on OSearch and IIS Admin Services.
The WPG group need to have permissions on Local Launch and Local Activate.