internal static void ValidateBindingReference(string binding, string bindingConfiguration, ContextInformation evaluationContext, ConfigurationElement configurationElement)
 {
     if (evaluationContext == null)
     {
         DiagnosticUtility.FailFast("ValidateBindingReference() should only called with valid ContextInformation");
     }
     if (!string.IsNullOrEmpty(binding))
     {
         BindingCollectionElement element = null;
         if (evaluationContext != null)
         {
             element = ConfigurationHelpers.UnsafeGetAssociatedBindingCollectionElement(evaluationContext, binding);
         }
         else
         {
             element = ConfigurationHelpers.UnsafeGetBindingCollectionElement(binding);
         }
         if (element == null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigInvalidSection", new object[] { ConfigurationHelpers.GetBindingsSectionPath(binding) }), configurationElement.ElementInformation.Source, configurationElement.ElementInformation.LineNumber));
         }
         if (!string.IsNullOrEmpty(bindingConfiguration) && !element.ContainsKey(bindingConfiguration))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigInvalidBindingName", new object[] { bindingConfiguration, ConfigurationHelpers.GetBindingsSectionPath(binding), "bindingConfiguration" }), configurationElement.ElementInformation.Source, configurationElement.ElementInformation.LineNumber));
         }
     }
 }
        internal static void ValidateBindingReference(string binding, string bindingConfiguration, ContextInformation evaluationContext, ConfigurationElement configurationElement)
        {
            // ValidateBindingReference built on assumption that evaluationContext is valid.
            // This should be protected at the callers site.  If assumption is invalid, then
            // configuration system is in an indeterminate state.  Need to stop in a manner that
            // user code can not capture.
            if (null == evaluationContext)
            {
                Fx.Assert("ValidateBindingReference() should only called with valid ContextInformation");
                DiagnosticUtility.FailFast("ValidateBindingReference() should only called with valid ContextInformation");
            }

            if (!String.IsNullOrEmpty(binding))
            {
                BindingCollectionElement bindingCollectionElement = null;

                if (null != evaluationContext)
                {
                    bindingCollectionElement = ConfigurationHelpers.UnsafeGetAssociatedBindingCollectionElement(evaluationContext, binding);
                }
                else
                {
                    bindingCollectionElement = ConfigurationHelpers.UnsafeGetBindingCollectionElement(binding);
                }

                if (bindingCollectionElement == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigInvalidSection,
                                                                                                                            ConfigurationHelpers.GetBindingsSectionPath(binding)),
                                                                                                               configurationElement.ElementInformation.Source,
                                                                                                               configurationElement.ElementInformation.LineNumber));
                }

                if (!String.IsNullOrEmpty(bindingConfiguration))
                {
                    if (!bindingCollectionElement.ContainsKey(bindingConfiguration))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigInvalidBindingName,
                                                                                                                                bindingConfiguration,
                                                                                                                                ConfigurationHelpers.GetBindingsSectionPath(binding),
                                                                                                                                ConfigurationStrings.BindingConfiguration),
                                                                                                                   configurationElement.ElementInformation.Source,
                                                                                                                   configurationElement.ElementInformation.LineNumber));
                    }
                }
            }
        }