I am trying to update web.config using SPWebConfigModification and I am getting the following error:
Exception calling "ApplyWebConfigModifications" with "0" argument(s): "Object reference not set to an instance of an
object."
At line:11 char:1
+ $app.Parent.ApplyWebConfigModifications();
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : NullReferenceException
This is my powershell script:
$app = Get-SPWebApplication http://test:8000/
$mod = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification
$mod.Path = “configuration/SharePoint/WebPartLimits”
$mod.Name = “MaxZoneParts”
$mod.Value = “100”
$mod.Sequence = 0
$mod.Owner = “webpartmod”
$mod.Type = 1
$app.WebConfigModifications.Add($mod)
$app.update()
$app.Parent.ApplyWebConfigModifications();
I have verified that $app and $mod are not null. What else could be causing this error?