Tuesday, January 19, 2010

Troubleshooting “An unexpected error has occurred” in SharePoint

Typical scenario in SharePoint Projects on hosted environment where Developers don’t have access to server:

Developer 1: SharePoint is throwing “An unexpected error has occurred” without giving any other information.

Developer 2: Did you try updating your Web.Config ? You need to set CallStack to false and customErrors mode to “Off”

Developer 1: Duh, I would have done that first thing if I had access to the server. I am working on a hosted SharePoint environment. I don’t have remote access to the machine, the event viewer and log files.

Developer 2: Then you are gone. Nothing can be done.

Developer 1: Oh God, Please Help Me!

You may face such scenarios in your project, don’t get tensed and give up. You need patience and common sense in such situations.

You can try to identify the root cause of the error in a methodical manner.

Step 1: Determine whether the error is at page level, page layout or master page.

Browse through different pages created using same layout. If the error is observed on Page A but not on Page B, the error is most likely on page A.

Browse through pages created using different layout. If error is observed on pages based on layout X, but not on pages based on layout Y, the error is most likely with the page layout X.

Temporarily change your Site or System master page. If changing the master page fixes the error, the error is most likely on the master page.

Step 2: Identify the control throwing the error.

Create a temporary copy of the page/ page layout / master page.

On the temporary copy, keep deleting chunks of code (table, div tag, control, webpart) and refresh the page in the browser till your page starts working. If your page stopped throwing error after removing control X, the error is likely to be in control X.

You can also do the reverse by starting with a blank page layout or master page, and adding controls one at a time till your page breaks.

Step 3: Fix the broken or corrupted control.

Once the control throwing error has been identified, your job is easier. Look for invalid attributes, properties, missing tags, dependencies, compare with implementation in default or other custom pages.

This simple approach has helped us troubleshoot issues on multiple occasions.

Developer 1: I found the issue, and fixed it.
Developer 2: Wow! You are the real SharePoint Guru.
Client: Great work. You are rock stars!

Note: Do not forget to hide your temporary pages from navigation while you are troubleshooting. And do not forget to delete them once you are done.

1 comment:

Rajesh Mangal said...

How to get "An unexpected error has occured" error in SharePoint? :)

Nice blog Vinay.