0

I am trying to build a Powershell script to automate connection string changes to our deployed web applications.

I am trying to use the WebAdministration command Set-WebApplicationProperty but am recieving an error about an Unrecognized element: 'providerOption'

PS IIS:\Sites\Default Web Site\VirtualPath> Set-WebConfigurationProperty "//connectionStrings/*[@name='DefaultConnection']" -Name ConnectionString -Value "<NEW CONNECTION STRING>" -PSPath (Get-Location).Path
Set-WebConfigurationProperty : Filename: \\?\C:\Windows\Microsoft.NET\Framework64\v4.0.30319\CONFIG\web.config
Line number: 53
Error: Unrecognized element 'providerOption'
At line:1 char:1
+ Set-WebConfigurationProperty "//connectionStrings/*[@name='DefaultConnection']"  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-WebConfigurationProperty], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.IIs.PowerShell.Provider.SetConfigurationPropertyCommand

I found some information about the same error on StackOverflow, but it appears to be related to the original release of .NET 4.0 : https://stackoverflow.com/questions/21308965/unrecognized-element-provideroption

Some additional environment information:

OS: Windows Server 2008 R2
IIS: 7.5
Powershell: v4.0
.NET Framework Version: 4.5.2

Also worth noting is that this command works just fine on Window 8.1, IIS 8.5, Powershell 4.0, .NET 4.5.2

EDIT: On a hunch I compared the Web.config specified in the error between a machine which works and a machine which does not. They are identical.

  • Did you import the module first and compare .net versions? – Colyn1337 Sep 19 '14 at 16:41
  • Yes indeed. I have the solution now, I'll post it in a moment. – Jesan Fafon Sep 22 '14 at 15:27
3

As it turns out, using Powershell was a red herring. IIS utilizes the files located in C:\Windows\System32\inetsrv\config\schema to validate the various xml config files the web server works with. On IIS 7 and IIS 7.5, FX_schema.xml is missing the declarations for providerOption.

My work-around is to patch the schema file by adding another file to this directory named "FX_schema.patch.xml" with the following contents:

<!--

    IIS 7.0 and IIS 7.5 contain incorrect system.codedom sections in their FX_schema.xml files.
    This version was taken from IIS 8.5 and contains the correct validations for the default web.config 
    in the CLR 4.0 folder. This file is only required on Windows Vista, 7, Server 2008 and Server 2008 R2.

-->
<configSchema>
    <sectionSchema name="system.codedom">
        <element name="compilers">
            <collection addElement="compiler" removeElement="remove" clearElement="clear">
                <attribute name="language" type="string" isCombinedKey="true" />
                <attribute name="extension" type="string" isCombinedKey="true" />
                <attribute name="type" type="string" />
                <attribute name="warningLevel" type="int" />
                <attribute name="compilerOptions" type="string" />
        <collection addElement="providerOption" >
                    <attribute name="name" type="string"  isCombinedKey="true" />
                    <attribute name="value" type="string" isCombinedKey="true" />
                </collection>
            </collection>
        </element>
    </sectionSchema>
</configSchema>

This file is merged with the existing FX_schema.xml and allows my WebAdministration commands to complete successfully.

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.