I’m processing a web.config file using XML and trying to remove certain appsetting add key/values entires. I use the following code below:
$_.key -ne $null -and $commonAppSettings -contains $_.key
The problem is when it attempt to execute the RemoveChild(), it throws the following error:
Exception calling "RemoveChild" with "1" argument(s): "Object reference not set to an instance of an object."
At C:\ws\coreServices\BuildProcessTemplates\Deployment\CoreDeploy.ps1:98 char:49
+ $config.configuration.appSettings.RemoveChild <<<< ($_.Node)
+ CategoryInfo : NotSpecified: (:) , MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
How do I properly reference the childnode to remove it?
Not having the whole script, it's a little hard to see what is going wrong but the error message is telling you that $config.configuration.appSettings object is not initialized.
Take a look at this posting and see it gives you some context to help solve your problem: