2

Trying to debug FeatureUpgrading event receiver on Sharepoint 2013. Attached localy to all w3wp.exe processes. After run

$MyFeature.Upgrade($true)

feature get upgraded, but breakpoint inside FeatureUpgrading wasn't hit. Any ideas?

UPD: upgrading feature with following powershell code:

Update-SPSolution -Identity MySolution.wsp -LiteralPath c:\distr\MySolution.wsp -GACDeployment
$w = Get-SPWeb http://MyPortal/sites/dev
$fn = $w.Features | where{$_.definition.displayname -like '*MySolution*'}
$fn.Upgrade($true)
$fn.Version

At the end I get the new version number from $fn.Version

  • how exactly you upgraded the feature and how you confirmed the feature actually upgraded? Could you please add those info? – SPArchaeologist Jan 28 '15 at 9:09
  • Did you attach PowerShell.exe process? – Nadeem Yousuf Jan 28 '15 at 9:22
  • Just tried to attach to both w3wp.exe and powershell processes. After started upgrade I got message in ManagementShell from SharePoint saying about error in my code, but still breakpoint in event receiver wasn't hitted... – Chetvergov Jan 28 '15 at 9:31
  • Make sure configuration is set to debug and not release. – Nadeem Yousuf Jan 28 '15 at 9:45
  • it is set to Debug – Chetvergov Jan 28 '15 at 11:22
3

Based on the information found on this blog you actually have to attach to the PowerShell process if you upgrade your feature like you did.

. Simply pressing F5 in Visual Studio will deploy the solution, launch the browser window and attach the debugger to the w3wp.exe process.

However, upgrading the feature is done in PowerShell. Running the PowerShell commands at this point will not result in any breakpoints in the event receiver being hit. In order to hit the breakpoints, you must attach Visual Studio to the PowerShell process. Additionally, if you keep the PowerShell window open, redeploy the solution with code changes in the event receiver and then use the same PowerShell window to test the Feature upgrade, you will be disappointed to find that the code changes have been picked up. This is because the Feature event receiver assembly is loaded into the PowerShell AppDomain and will not be unloaded until you open a new PowerShell window.

Also, if anything else fails, consider using Debuger.Launch(). This also avoid the necessity to manually attach to the process every time you want to debug.

  • Succeed with "Debuger.Launch()" command. Thanks! – Chetvergov Jan 28 '15 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.