Allow Debugging for SharePoint

Problem

At some point SharePoint developers will need to trace, log and debug their code when they get tripped up with bugs or any weird things when building custom solutions, applications, or components for SharePoint. 

Solution

1.  Enable debug information and tracing over bugs and exceptions on WSS (Windows SharePoint Services) 3.0 & MOSS (Microsoft Office SharePoint Server) 2007:

We can allow debugging/tracing in SharePoint 2007 by using the multiple approaches below:

I. "Debugging with VSEWSS (Visual Studio Extensions For Windows SharePoint Services)": [F5 Debugging]
  1. Locate and open the target SharePoint applications "Web.Config" file . (Usually located at: "C:/Inetpub/wwwroot/wss/VirtualDirectoties/<port_number_of_Web application>").
  2. Search and find the below line of code and change "debug" attribute to "true" then save the change:
    <compilation batch="false" debug="false"> into <compilation batch="false" debug="true">
  3. Search and find the below line of code and change "CallStack" attribute to "true" then save the changes:
    <SafeMode MaxControls="200" CallStack="false" ...> into <SafeMode MaxControls="200" CallStack="true" ...>
  4. Search and find the below line of code and change "mode" attribute to "Off" then save the changes:
    <customErrors mode="On" /> into <customErrors mode="Off" />
  5. Then in Visual Studio, Right click the SharePoint Project and then click properties.
  6.  Click the "Debug" tab then type the target SharePoint URL in the 'start browser with URL' box. Then, place a breakpoint either by clicking on the line of code or pressing F9 on the selected line of code and then press "F5".

II. "Manual Debugging": [w3wp.exe Attach to Process]

We can debug SharePoint applications without using VSEWSS [F5 Debugging] by attaching to the w3wp.exe process by using the following procedures:

  1. The SharePoint application must use the latest compiled source code. We need to recompile the source code and install the assemblies into the GAC (Global Assembly Cache - usually located at: C:/Windows/assembly). Alternatively, we may need to copy the assemblies to the bin folder of the SharePoint virtual directory. This is usually located at: "C:/Intepub/wwwroot/wss/VirtualDirectories/<port_number_of_web application>/bin". In either case we must run  the Microsoft Internet Information Services (IIS) command-line utility "iisreset.exe" by opening a command prompt and typing "iisreset".
  2.  Place a breakpoint in the code that we want to debug.
  3.  Click on the "Debug" menu then click "Attach to Process".
  4.  In the list of available processes, find the W3wp.exe process and then do the following, as applicable:
    •  If the W3wp.exe process is not listed make sure that the "Show processes from all users" & "Show processes in all sessions" check boxes are selected.
    •  If the W3wp.exe process is still not listed, open a web browser and navigate to the application SharePoint site. Then return to the Visual Studio, then "Attach to process" and click the refresh button to locate the W3wp.exe process.
    •  If you see multiple W3wp.exe process listed and ae not sure which one is running the code, we can click them all or open a "cmd" window and type "iisapp" towhich W3wp.exe process number is mapped to our web application port number.
    •  Click the Attach button.
III. "Remote Debugging": [W3wp.exe Remote Attach to Process]

We can debug a SharePoint application which is running on a remote computer by attaching to the remote W3wp.exe process by using the following procedures:

  1. Repeat step (1) at "Manual Debugging".
              
  2. Make sure that the Visual Studio remote debugger is installed on the remote computer and then start the remote debugger monitor.
              
  3.  Then open Visual Studio on the local computer and open the solution. Then set the breakpoints.
              
  4.  Click on the Debug menu. Then click on "Attach to process". Then in the Qualifier text box, type the name of the remote computer and then click Refresh.
              
  5.  Then in the Available Processes list , find the W3wp.exe process then repeat step (4) at "Manual Debugging".

2.Enable debug information and tracing over bugs and exceptions on SharePoint 2010 :

In WSS 3.0 / MOSS 2007, to allow debugging, we have to modify only the Web.Config which relates to your web application. But in SharePoint 2010, we have to modify two different Web.Config files by following the steps below:

I. Virtual Directory Web.Config File

 If we opened the target SharePoint solution using Visual Studio.net 2010 then select Debug or click F5, Visual Studio will prompt with a dialog box that alerts that the Web.Config file is not configured to enable debugging. The dialog box gives us the option of either running the project without debugging or modifying the Web.Config file to enable debugging.If we select the first option, the project runs normally. But if we select the second option the Web.Config file is configured to :             

  •  Turn on the Call Stack (CallStack="true")             
  •  Disable the custom errors in Visual Studio (<CustomErrors mode="Off">)             
  •  Enable compilation debug (<compilation debug="true">)

Note that:

We can configure the debugging manually as we did at Part 1 via:

  • Locate and open the "Web.Config" file . (Usually located at : "C:/Inetpub/wwwroot/wss/VirtualDirectoties/<port_number_of_Web application>") .
  •  Search and find the line of code (below) and change the "debug" attribute to "true" and then save the changes :
    <compilation batch="false" debug="false">   into <compilation batch="false" debug="true">
  •  Search and find the following line of code and change the "CallStack" attribute to "true" and then save the changes :
    <SafeMode MaxControls="200" CallStack="false" ...>   into <SafeMode MaxControls="200" CallStack="true" ...>
  • Search and find the following line of code and change the "mode" attribute to "Off" and then save the changes:
    <customErrors mode="On" /> into <customErrors mode="Off" />
     
II. "LAYOUTS Web.Config File":
  •  Locate and open the LAYOUTS "Web.Config" file . (Usually located at : "C:/Program Files/Common Files/Microsoft Shared/Web Server Extensions/14/Template/Layouts") .
  •  Search and find the following line of code and change the "mode" attribute to "Off" and then save the changes:
    <customErrors mode="On" /> into <customErrors mode="Off" />

Note that:

According to the complex interactions between Visual Studio processes (of 'devenv.exe' and 'vssphost4.exe'), and the SharePoint and WCF layers, diagnosing errors that occur while building, deploying, etc...can be a challenge. In order to solve such errors, we can enable the enhanced debugging information by following the steps below:

  •  Go to the registry (Run > Regedit) in the windows registry.
  •  Go to [HKEY_CURRENT_USER/Software/Microsoft/VisualStudio/10.0/SharePointTools] .
  •  Right Click on SharePointTools and select Create new dword value. Name it "EnableDiagnostics" for the key and set the value from "0" to "1" (Setting this key value to "1" causes stack trace information to appear in the Output window "View (Menu) > Output" whenever project system errors occur while we are running in Visual Studio. To disable enhanced debugging information set the "EnableDiagnostics"  key value to "0".

其他参考资料:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值