How To Debug Custom Applications In SharePoint 2013

Introduction

This article is for beginner level Sharepoint developers and it explores how to debug SharePoint custom applications along with the standard ways to debug.

Debug a Microsoft SharePoint Custom Web part with Visual Studio

SharePoint custom visual web part is executed and debugged by the worker process which is a Windows process (w3wp.exe).

Here are the steps to debug a web part in SharePoint.

Step 1

Open the project and set appropriate breakpoints.

Step 2

Create a Web Part page on the default SharePoint site.

Step 3

Add the Web Part to the page.

Step 4

  • Attach the debugger to the W3wp
  • In the Debug menu in Visual Studio .NET, click "Processes".
  • Verify that the "Show system processes" check box is selected.
  • Verify that the "Show processes in all sessions" check box is selected.
  • Under "Available Processes", click exe in the Process list, and then click "Attach".
  • Under "Choose the program types that you want to debug", select Common Language Runtime. 
  • Now, click OK and then "Close".
  • Follow the below steps for finding the application related Work process,

    Open CMD -> cd C:\Windows\System32\inetsrv-> appcmd list wp

    Sharepoint
    Sharepoint

Debug a Microsoft SharePoint Timer Job with Visual Studio

SharePoint timer jobs are tasks executed on a scheduled basis by the Windows SharePoint Services timer service (owstimer.exe). They are analogous to scheduled tasks,

  1. First, deploy your solution containing your timer job to SharePoint. From Visual Studio, click "Build" and then "Deploy Solution".

    Sharepoint

  2. Open Windows Services. ( Click the "Start" button and type Services; or alternatively, this can be accessed from Control Panel > System and Security > Administrative Tools).

  3. Select the service namedSharePoint Timer Services. This ensures that the latest DLL is loaded for your timer job.

    Sharepoint

  1. From Visual Studio, attach the debugger to the process named OWSTIMER.EXE. To do so, select "Debug and Attach to Process". You may need to tick the check box "Show processes from all users" to find OWSTIMER.EXE.

    Sharepoint