If you use custom webconfig files under 14/CONFIG folder to modify web application’s web.config file, then pay attention not to include any XML comment <!-- --> in the xml files.

Neither Install-SPApplicationContent nor STSADM –o copyappbincontent parse xml comments.

 

For example:

in 14/CONFIG/webconfig.custom.xml,  

   1: <?xml version="1.0" encoding="utf-8"?>
   2: <actions>
   3:   <remove path="configuration/appSettings/add[@key='Security.ServiceAccount']" />
   4:  
   5:   <!-- XML COMMENT CANNOT BE PARSED -->
   6:   
   7:   <add path="configuration/appSettings">
   8:     <add key="Security.ServiceAccount" value="apac\spadmin" />
   9:   </add>
  10: </actions>

 

Now if you run STSADM –o copyappbincontent, you would get the following error:

Object reference not set to an instance of an object.

 

If you run Install-SPApplicationContent, you would get the following erro:

Install-SPApplicationContent : Object reference not set to an instance of an ob
ject.
At line:1 char:29
+ Install-SPApplicationContent <<<<
    + CategoryInfo          : InvalidData: (Microsoft.Share...licationContent:
   SPCmdletInstallSPApplicationContent) [Install-SPApplicationContent], NullR
  eferenceException
    + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletInstallS
   PApplicationContent

 

Remove the xml comment at line 5 in 14/CONFIG/webconfig.custom.xml will resolve this error.