Feature is shown as Active but code in FeatureActivated is never executed after activating via PowerShell
-
2010年11月11日 15:15
I've had a powershell script to activate my features for several weeks. However since a few days one feature behaves pretty strange as it's shown as activated after the script is finished, but the code inside FeatureActivated has never been executed.
If I activate the feature via "site settings" -> "site collection features" or via Visual Studio 2010 every works fine and 5 other features are activated properly via PowerShell script but somehow this one feature acts differently.
Does anyone have a suggestion where to start looking at?
全部回复
-
2010年11月11日 17:02
1. Look at the code. If the code uses SPContext.Current, it's poorly designed and won't execute outside the web context.
2. Make sure the code is in the GAC. Otherwise powershell won't find it.
Daniel Larson SharePoint Architect at NewsGator Technologies, Author for Microsoft Press, Father of VI and Eli -
2010年11月12日 8:13
Hey Daniel,
thanks for your reply. Could you please provide some more informations or links for your first suggestion as I'm a little bit confused by it. In this case I'm using
in my feature receiver. However that's the same for all features I'm using.public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPSite currentSite = (SPSite)properties.Feature.Parent; SPWeb currentWeb = currentSite.RootWeb; ... }
For your 2nd suggestion: I'll check if my code is available in GAC, but since I can activate the feature via site settings -> sitecollection features I guess everything is available and fine.
-
2010年11月12日 15:17
That code looks fine. Check to see if anywhere has references to SPContext.Current, including code you are calling,
You could also throw a thread.sleep command in the receiver, run the powershell command and then connect to the process to debug.
>> I'll check if my code is available in GAC, but since I can activate the feature via site settings -> sitecollection features I guess everything is available and fine.
Not necessarily.... code in the web app bin directory can run as feature receivers (SHOULDN'T but will work...) so check WHERE you're deploying the code. As a rule, anything that runs as a feature receiver needs to be GAC deployed.
Daniel Larson SharePoint Architect at NewsGator Technologies, Author for Microsoft Press, Father of VI and Eli -
2010年11月15日 8:37
Hey, I don't use SPContext.Current anywhere in my solution (although beside my problem I'm wondering if you could provide some more informations about "the poor design" of it) and yes the my solution is deployed to GAC. Activating the feature via Visual Studio 2010 also works just fine.
It's only the activation via PowerShell which seems to struggle, while User Interface and Visual Studio continue working and it's one out of four solutions which started having problems.
-
2010年11月15日 20:15
You need to debug it to find out what's happening.
You could throw a thread.sleep command in the receiver, run the powershell command and then connect to the process to debug.
Or write a console app that activates the feature, and step in with the debugger.
Debugging your application when it doesn't work should be a first step...
Daniel Larson SharePoint Architect at NewsGator Technologies, Author for Microsoft Press, Father of VI and Eli- 已建议为答案 daniel.larson 2010年11月17日 16:07
- 已标记为答案 Wayne Fan 2010年11月19日 3:07
-
2010年11月15日 20:17
re: I don't use SPContext.Current anywhere in my solution (although beside my problem I'm wondering if you could provide some more informations about "the poor design" of it)
You can use SPContext in web parts or web code when you know there is an SPContext. But if a feature is activated outside of the web app, SPContext.Current will be null-- so code that can be called outside of a web app can't reliably use SPContext.Current.
Daniel Larson SharePoint Architect at NewsGator Technologies, Author for Microsoft Press, Father of VI and Eli

