Share via


An extension of name clientcredentials already appears in extension collection, extension name must be unique.

When we browse the web page it loads fine and continues working. Once we close the IIS manager and open it again, the following section gets added to the web.config file automatically :

<extensions>

   <behaviorExtensions>

    <add name="clientCredentials" type="System.ServiceModel.Configuration.ClientCredentialsElement, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

    <add name="serviceCredentials" type="System.ServiceModel.Configuration.ServiceCredentialsElement, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

    <add name="callbackDebug" type="System.ServiceModel.Configuration.CallbackDebugElement, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

    <add name="clientVia" type="System.ServiceModel.Configuration.ClientViaElement, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

.....................

......................

......................

   </behaviorExtensions>

   <bindingElementExtensions>

    <add name="binaryMessageEncoding" type="System.ServiceModel.Configuration.BinaryMessageEncodingElement, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

    <add name="compositeDuplex" type="System.ServiceModel.Configuration.CompositeDuplexElement, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

    <add name="oneWay" type="System.ServiceModel.Configuration.OneWayElement, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

...................

..................

..................

   </bindingElementExtensions>

   <bindingExtensions>

    <add name="basicHttpBinding" type="System.ServiceModel.Configuration.BasicHttpBindingCollectionElement, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

    <add name="customBinding" type="System.ServiceModel.Configuration.CustomBindingCollectionElement, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

    <add name="msmqIntegrationBinding" type="System.ServiceModel.Configuration.MsmqIntegrationBindingCollectionElement, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

..............

................

................

..................

   </bindingExtensions>

  </extensions>

And now, when we browse the web page we get the exception :

"An extension of name clientcredentials already appears in extension collection, extension name must be unique.”

Resolution

We collected first chance exception dumps and process monitor log files when the issue occurred. The analysis from the dumps :

System_Configuration_ni!System.Configuration.Internal.WriteFileContext.DuplicateTemplateAttributes

System_Configuration_ni!System.Configuration.Internal.WriteFileContext.DuplicateFileAttributes(

System_Configuration_ni!System.Configuration.Internal.WriteFileContext.Complete

System_Configuration_ni!System.Configuration.Internal.InternalConfigHost.StaticWriteCompleted

System_Configuration_ni!System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.WriteCompleted

System_Configuration_ni!System.Configuration.Internal.DelegatingConfigHost.WriteCompleted

System_Configuration_ni!System.Configuration.UpdateConfigHost.WriteCompleted

System_Configuration_ni!System.Configuration.MgmtConfigurationRecord.SaveAs

System_Configuration_ni!System.Configuration.Configuration.SaveAsImpl(System.String, System.Configuration.ConfigurationSaveMode, Boolean)

System_Configuration_ni!System.Configuration.Configuration.Save(System.Configuration.ConfigurationSaveMode, Boolean)System_Web_ni!System.Web.UI.Control.OnLoad(System.EventArgs)

System_Web_ni!System.Web.UI.Control.LoadRecursive()

System_Web_ni!System.Web.UI.Page.ProcessRequestMain

System_Web_ni!System.Web.UI.Page.ProcessRequest(Boolean, Boolean)

System_Web_ni!System.Web.UI.Page.ProcessRequest()

System_Web_ni!System.Web.UI.Page.ProcessRequestWithNoAssert

System_Web_ni!System.Web.UI.Page.ProcessRequest

System_Web_ni!System.Web.HttpApplication+CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()

System_Web_ni!System.Web.HttpApplication.ExecuteStep

System_Web_ni!System.Web.HttpApplication+ApplicationStepManager.ResumeSteps

System_Web_ni!System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest

System_Web_ni!System.Web.HttpRuntime.ProcessRequestInternal

System_Web_ni!System.Web.HttpRuntime.ProcessRequestNoDemand

System_Web_ni!System.Web.Hosting.ISAPIRuntime.ProcessRequest

So looks like we are loading some control on the web page and that control is saving some changes to the web.config file using Configuration.Save method.

In the source files, we found following line of code that was saving the config settings everytime the page was loaded :

        config.Save(ConfigurationSaveMode.Full, True)

We made the second parameter to false to avoid saving the changes everytime the page is loaded. After setting the second parameter to false we did not have the issue any more.

Reference

Configuration.Save Method (ConfigurationSaveMode, Boolean)

https://msdn.microsoft.com/en-us/library/system.configuration.configuration.save.aspx