title: ChannelFactory`1[BLLService], cannot be modified while it is in the Opening state
body: <p>I'm getting an exception in WCF. The problem is that I am randomly getting this exception in Windows service in WCF. Now since I cannot debug production server so I am using log4net for logging.</p>
  <p>The exception is random in time and in different functions. It Occurs few in a day with almost 400 to 1000 db entries. Now here is my proxy class code where I am checking the client open state.</p>
  <pre><code>public static BLLServiceClient bLLServiceClient
          {
              get
              {
                  if (_bLLServiceClient == null || _bLLServiceClient.State != CommunicationState.Opened)
                  {
       _bLLServiceClient = new BLLServiceClient(Common.GetBinding(_settings.BLLServiceBinding), new EndpointAddress(_settings.BLLServiceAddress));                        
       _bLLServiceClient.Open();
                  }                  
                  return _bLLServiceClient;
              }
              set
              {
                  _bLLServiceClient = value;
              }
          }
  </code></pre>
  <p>Which means if client is not in open state then open it or else return client</p>
  <p>The exception is</p>
  <pre><code>SetSiteDataStatusInDatabase:  ____ The communication object, System.ServiceModel.ChannelFactory`1[BLLService], cannot be modified while it is in the Opening state.
  System.ServiceModel
     at System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrImmutable()
     at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
     at System.ServiceModel.ChannelFactory.EnsureOpened()
     at System.ServiceModel.ChannelFactory`1.CreateChannel(EndpointAddress address, Uri via)
     at System.ServiceModel.ChannelFactory`1.CreateChannel()
     at System.ServiceModel.ClientBase`1.CreateChannel()
     at System.ServiceModel.ClientBase`1.CreateChannelInternal()
     at System.ServiceModel.ClientBase`1.get_Channel()
     at BLLServiceClient.UpdateData(SiteData eSiteData)
     at DataHelper.SetSiteDataStatusInDatabase(SiteData oSiteData, CurrentTaskStatus newStatus)
  Void ThrowIfDisposedOrImmutable()
  System.Collections.ListDictionaryInternal
   Full Exception....
  System.InvalidOperationException: The communication object, System.ServiceModel.ChannelFactory`1[ BLLService], cannot be modified while it is in the Opening state.
     at System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrImmutable()
     at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
     at System.ServiceModel.ChannelFactory.EnsureOpened()
     at System.ServiceModel.ChannelFactory`1.CreateChannel(EndpointAddress address, Uri via)
     at System.ServiceModel.ChannelFactory`1.CreateChannel()
     at System.ServiceModel.ClientBase`1.CreateChannel()
     at System.ServiceModel.ClientBase`1.CreateChannelInternal()
     at System.ServiceModel.ClientBase`1.get_Channel()
     at Proxy.BLLService.BLLServiceClient.UpdateData(SiteData eSiteData)
     at DataHelper.SetSiteDataStatusInDatabase(SiteData oSiteData, CurrentTaskStatus newStatus) 
  </code></pre>
  <p>Tried to search but couldn't find modified type exception</p>
  <h2 id="edit">Edit</h2>
  <p>After using @Agalo answer now the exception has changed to</p>
  <pre><code>   Exception of type 'System.OutOfMemoryException' was thrown.
  System
     at System.Uri.CreateHelper(String uriString, Boolean dontEscape, UriKind uriKind, UriFormatException&amp; e)
     at System.Uri.TryCreate(String uriString, UriKind uriKind, Uri&amp; result)
     at System.ServiceModel.Description.NamingHelper.CheckUriParameter(String ns, String paramName)
     at System.ServiceModel.Description.MessagePartDescription..ctor(String name, String ns)
     at System.ServiceModel.Description.TypeLoader.CreateParameterPartDescription(XmlName defaultName, String defaultNS, Int32 index, ICustomAttributeProvider attrProvider, Type type)
     at System.ServiceModel.Description.TypeLoader.CreateParameterMessageDescription(ParameterInfo[] parameters, Type returnType, ICustomAttributeProvider returnAttrProvider, XmlName returnValueName, String methodName, String defaultNS, String action, XmlName wrapperName, String wrapperNamespace, MessageDirection direction)
     at System.ServiceModel.Description.TypeLoader.CreateMessageDescription(MethodInfo methodInfo, Boolean isAsync, Boolean isTask, Type taskTResult, XmlName returnValueName, String defaultNS, String action, XmlName wrapperName, String wrapperNamespace, MessageDirection direction)
     at System.ServiceModel.Description.TypeLoader.CreateOperationDescription(ContractDescription contractDescription, MethodInfo methodInfo, MessageDirection direction, ContractReflectionInfo reflectionInfo, ContractDescription declaringContract)
     at System.ServiceModel.Description.TypeLoader.CreateOperationDescriptions(ContractDescription contractDescription, ContractReflectionInfo reflectionInfo, Type contractToGetMethodsFrom, ContractDescription declaringContract, MessageDirection direction)
     at System.ServiceModel.Description.TypeLoader.CreateContractDescription(ServiceContractAttribute contractAttr, Type contractType, Type serviceType, ContractReflectionInfo&amp; reflectionInfo, Object serviceImplementation)
     at System.ServiceModel.Description.TypeLoader.LoadContractDescriptionHelper(Type contractType, Type serviceType, Object serviceImplementation)
     at System.ServiceModel.ChannelFactory`1.CreateDescription()
     at System.ServiceModel.ChannelFactory.InitializeEndpoint(Binding binding, EndpointAddress address)
     at System.ServiceModel.ChannelFactory`1..ctor(Binding binding, EndpointAddress remoteAddress)
     at System.ServiceModel.ClientBase`1..ctor(Binding binding, EndpointAddress remoteAddress)
     at BLLServiceClient..ctor(Binding binding, EndpointAddress remoteAddress)
     at ServiceClients.get_bLLServiceClient()
     at SiteDataHelper.get_bLLServiceClient()
     at SiteDataHelper.FetchFilesListToDownload(Int32 siteDataId)
  System.Uri CreateHelper(System.String, Boolean, System.UriKind, System.UriFormatException ByRef)
  System.Collections.ListDictionaryInternal
   Full Exception....
  System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
     at System.Uri.CreateHelper(String uriString, Boolean dontEscape, UriKind uriKind, UriFormatException&amp; e)
     at System.Uri.TryCreate(String uriString, UriKind uriKind, Uri&amp; result)
     at System.ServiceModel.Description.NamingHelper.CheckUriParameter(String ns, String paramName)
     at System.ServiceModel.Description.MessagePartDescription..ctor(String name, String ns)
     at System.ServiceModel.Description.TypeLoader.CreateParameterPartDescription(XmlName defaultName, String defaultNS, Int32 index, ICustomAttributeProvider attrProvider, Type type)
     at System.ServiceModel.Description.TypeLoader.CreateParameterMessageDescription(ParameterInfo[] parameters, Type returnType, ICustomAttributeProvider returnAttrProvider, XmlName returnValueName, String methodName, String defaultNS, String action, XmlName wrapperName, String wrapperNamespace, MessageDirection direction)
     at System.ServiceModel.Description.TypeLoader.CreateMessageDescription(MethodInfo methodInfo, Boolean isAsync, Boolean isTask, Type taskTResult, XmlName returnValueName, String defaultNS, String action, XmlName wrapperName, String wrapperNamespace, MessageDirection direction)
     at System.ServiceModel.Description.TypeLoader.CreateOperationDescription(ContractDescription contractDescription, MethodInfo methodInfo, MessageDirection direction, ContractReflectionInfo reflectionInfo, ContractDescription declaringContract)
     at System.ServiceModel.Description.TypeLoader.CreateOperationDescriptions(ContractDescription contractDescription, ContractReflectionInfo reflectionInfo, Type contractToGetMethodsFrom, ContractDescription declaringContract, MessageDirection direction)
     at System.ServiceModel.Description.TypeLoader.CreateContractDescription(ServiceContractAttribute contractAttr, Type contractType, Type serviceType, ContractReflectionInfo&amp; reflectionInfo, Object serviceImplementation)
     at System.ServiceModel.Description.TypeLoader.LoadContractDescriptionHelper(Type contractType, Type serviceType, Object serviceImplementation)
     at System.ServiceModel.ChannelFactory`1.CreateDescription()
     at System.ServiceModel.ChannelFactory.InitializeEndpoint(Binding binding, EndpointAddress address)
     at System.ServiceModel.ChannelFactory`1..ctor(Binding binding, EndpointAddress remoteAddress)
     at System.ServiceModel.ClientBase`1..ctor(Binding binding, EndpointAddress remoteAddress)
     at BLLServiceClient..ctor(Binding binding, EndpointAddress remoteAddress)
     at ServiceClients.get_bLLServiceClient()
     at SiteDataHelper.get_bLLServiceClient()
     at SiteDataHelper.FetchFilesListToDownload(Int32 siteDataId)
  </code></pre>