Goal of this post
This post sums up all the different methods to get handy information when you need to debug a SharePoint piece of code.
As a reminder, when an error occurs in a SharePoint page, the inexplicit error message appears:
Fortunately, you are able to display debug information, stack traces, detailed error messages, and more…
Solution, and many more
1. Set CustomError mode to Off and CallStack to true
When the message above occurs, the first step to execute is to configure the CustomError mode and the CallStack parameters in your web.config file:
at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
You are now able to determine which instruction had caused the error and what is the real error message.
2. Display trace
When developing SharePoint applications or pages, even if the page builds successfully, you may need more information on the server variables, the headers, the forms post values, the cookies, the page web controls, the request trace, etc…
This feature natively exists in ASP.NET; you just have to enable it into your web application configuration and activate it on a specific page, or into the web.config file of your Web application:
Allow trace on a specific page:
Allow trace on the entire web site:
3. Using Visual Studio debugger
SharePoint developments can be debugged like console applications or windows applications by configuring the Visual Studio debugger.
Tip: you can attach your debugger to all the w3wp.exe processes, or determine which process is used by your current portal web application by opening a command prompt, and executing the following command:
Once you have found the Application ID, you just have to attach your project to the right w3wp.exe process (the one that executes your current portal web application):
If you want to have more details about debugging tips within Visual Studio, you can find more documentation on MSDN:
Tip: when debugging a custom workflow, remember to select Workflow as code type when attaching the process. Otherwise, Visual Studio may crash without explicit error message.
4. Looking for LOG files
Depending on your diagnostic logging configuration (see Central Administration > Operations > Diagnostic logging), SharePoint can log events on text files located by default in: "C:\Program Files\Common files\Microsoft Shared\web server extensions\12\LOGS"
For instance, if you have to debug a custom Workflow developed with Visual Studio, open the last log file (by sorting them by date), place your cursor at the end of the file, and search for workflow infrastructure (direction: top). You'll see the detailed error that occurred while executing your workflow.
5. Write your own custom trace in SharePoint log files
Source code and usage sample can be found at the following MSDN url: