internal static BindingCollectionElement UnsafeGetAssociatedBindingCollectionElement(ContextInformation evaluationContext, string bindingCollectionName) { BindingCollectionElement retVal = null; BindingsSection bindingsSection = (BindingsSection)ConfigurationHelpers.UnsafeGetAssociatedSection(evaluationContext, ConfigurationStrings.BindingsSectionGroupPath); if (null != bindingsSection) { bindingsSection.UpdateBindingSections(evaluationContext); try { retVal = bindingsSection[bindingCollectionName]; } catch (KeyNotFoundException) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new ConfigurationErrorsException(SR.GetString(SR.ConfigBindingExtensionNotFound, ConfigurationHelpers.GetBindingsSectionPath(bindingCollectionName)))); } catch (NullReferenceException) // System.Configuration.ConfigurationElement { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new ConfigurationErrorsException(SR.GetString(SR.ConfigBindingExtensionNotFound, ConfigurationHelpers.GetBindingsSectionPath(bindingCollectionName)))); } } return(retVal); }
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)); } } }
protected override bool OnDeserializeUnrecognizedElement(string elementName, XmlReader reader) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigBindingExtensionNotFound", new object[] { ConfigurationHelpers.GetBindingsSectionPath(elementName) }))); }
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)); } } } }