Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top