Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I just created a new WebApplication & Site Collection in sharepoint.

Note : WebApplication uses Claims Authentication mode, Custom Trusted Identity Provider for my application.

In powershell when i try to access $site.RootWeb.AllProperties it is returning null

$site.RootWeb.AllProperties.Add("a", "1")

You cannot call a method on a null-valued expression. At line:1 char:21

+ $site.RootWeb.AllProperties.Add <<<< ("a","1")

+ CategoryInfo : InvalidOperation: (Add:String) [], RuntimeException

+ FullyQualifiedErrorId : InvokeMethodOnNull

Does anyone knows why this occurs?

share|improve this question
    
This happens only on web applications with claims based authentication and not on integrated authentication. –  BalajiG Jan 7 '13 at 6:54

2 Answers 2

This blog provides a good overview of how to work with the SPWeb property bag while also providing links to MSDN. http://bramnuyts.be/2012/01/10/working-with-spwebs-propertybag/

The root of your problem, it seems, is that you are doing SPWeb.AllProperties.Add() instead of SPWeb.AddProperty()

share|improve this answer
    
Am getting the same error. See the reflected AddProperty method below public void AddProperty(object key, object value) { this.AllProperties.Add(key, value); } PS C:\windows> $w.AddProperty("a","1") Exception calling "AddProperty" with "2" argument(s): "Access is denied. (Excep tion from HRESULT: 0x80070005 (E_ACCESSDENIED))" At line:1 char:15 + $w.AddProperty <<<< ("a","1") + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException –  BalajiG Jan 7 '13 at 6:30
    
Hey at least this approach exposed an access denied error which is much easier to troubleshoot :) –  SpartanDonut Jan 7 '13 at 14:52
    
I got this access denied error before also while trying the same in a console application also. Yes really that helped a lot in analysing the issue. Thanks reaaaaally a lot for your help. –  BalajiG Jan 8 '13 at 10:30
up vote 0 down vote accepted

Getting the site using Elevated Privileges fixed the problem

PS C:\windows> [Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges({$s = get-spsite "http://balajig-01"})
PS C:\windows> $s.RootWeb.AllProperties


Name                           Value
----                           ----- 
vti_associatemembergroup       5
vti_extenderversion            14.0.0.6120
vti_associatevisitorgroup      4
vti_associategroups            5;4;3
vti_createdassociategroups     3;4;5
vti_approvallevels             Approved Rejected Pending\ Review
vti_categories                 Travel Expense\ Report Business Competition G...
vti_associateownergroup        3
vti_defaultlanguage            en-us

Thanks anyways

share|improve this answer
    
This would make sense. I'm generally running powershell as site collection or farm admin and don't have a need for that. Good catch. –  SpartanDonut Jan 7 '13 at 14:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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