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?

  • This happens only on web applications with claims based authentication and not on integrated authentication. – Balaji Gunasekaran Jan 7 '13 at 6:54

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()

  • 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 – Balaji Gunasekaran 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. – Balaji Gunasekaran Jan 8 '13 at 10:30

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_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

  • 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

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.