System.ArgumentException: an element with the same key has already been added
I configured ADFS on Windows Server 2012 and when I tried to access https://abc-idfs.cloudapp.net/adfs/ls/IdpInitiatedSignOn.aspx I got the error:
Exception details:
System.ArgumentException: An item with the same key has already been added.
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at Microsoft.IdentityServer.Web.HomeRealmModule.FindApplicableRealms(ProtocolContext context, Boolean needsIDPInstance)
at Microsoft.IdentityServer.Web.HomeRealmModule.DiscoverHomeRealm(PassiveProtocolHandler pHandler, ProtocolContext context)
at Microsoft.IdentityServer.Web.PassiveProtocolListener.GetAuthenticationMethods(PassiveProtocolHandler protocolHandler, ProtocolContext protocolContext)
at Microsoft.IdentityServer.Web.PassiveProtocolListener.OnGetContext(WrappedHttpListenerContext context)
I can't figure out where I am going wrong
source to share
This has happened to me several times while setting up new ADFS servers from scratch. In my case, I have powershell code that installs the server, but it always gave me this error after running the script, so I knew it was something in the configuration and not from ADFS itself.
So in the end the problem was in my case: Requirements provider id should have https: // instead of http: //
To verify the value of this parameter, open the AD FS administration interface, expand Trusts, Target Vendor Trusts, select the claims provider and right-click and select properties, then go to the IDs tab and view the claims provider ID - if it doesn't matter https: // and you are using certs to handle service messages, you will get event ID 364 in your logs with this exact message.
364 can arise for a number of reasons, not just the one I mention here, but the problem is so simple that it can be easily overlooked. Hope this helps someone.
source to share