.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

ServiceModel ObjectDisposedException

Posted By:      Posted Date: September 10, 2010    Points: 0   Category :WCF
Every now and then I see this wcf error on the server hosting my per call wcf service (.net 4.0, net.tcp, IIS7, WAS):   TypeName: System.ObjectDisposedException TypeAssembly: mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message: Cannot access a disposed object. Object name: 'System.ServiceModel.Channels.ServerSessionPreambleConnectionReader+ServerFramingDuplexSessionChannel'. Source: System.ServiceModel TargetSite: Void ThrowIfDisposedOrNotOpen() StackTrace:    at System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrNotOpen()    at System.ServiceModel.Channels.OutputChannel.Send(Message message, TimeSpan timeout)    at System.ServiceModel.Dispatcher.DuplexChannelBinder.DuplexRequestContext.OnReply(Message message, TimeSpan timeout)    at System.ServiceModel.Channels.RequestContextBase.Reply(Message message, TimeSpan timeout)    at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.Reply(MessageRpc& rpc) ObjectName: System.ServiceModel.Channels.ServerSessionPreambleConnectionReader+ServerFramingDuplexSessionChannel     The corresponding client side error is this: TypeName: System.ServiceModel.CommunicationException TypeAssembly: System.ServiceModel, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message: The server did not provide

View Complete Post

More Related Resource Links

System.ServiceModel.ServiceActivationException was unhandled

I've got a very, very simple WCF service. I'm hosting on Windows 08 with IIS7. The site is setup as such: E:\inetpub\wwwroot\WCFServices\FService --- permissions are good The contents of the FService is: 1. \bin -- an assembly 2. FService.svc -- <%@ServiceHost language="c#"  Debug="true"  Service="Company.Unit.Section.FService" %> 3. web.config -- <?xml version="1.0" encoding="utf-8"?> <configuration>   <connectionStrings>     <add name="fConnectionString" connectionString="Data Source=servername,25654;Initial Catalog=dbname;Persist Security Info=True;User ID=user;Password=password" providerName="System.Data.SqlClient" />   </connectionStrings>   <system.serviceModel>          <bindings>           <wsHttpBinding>               <binding name="WSHttpBinding_IFService" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="

System.ServiceModel.Activation.WebScriptServiceHostFactory (using this how can i increase the maxrec

using the System.ServiceModel.Activation.WebScriptServiceHostFactory (which does not need configuration) how can i increase the maxreceived message size ? can i do this in code behind???

Problem with DuplexChannelFactory(System.ServiceModel.InstanceContext, System.ServiceModel.Descripti

I have derived a class from DuplexChannelFactory, and one of the constructors of the derived class takes System.ServiceModel.InstanceContext and System.ServiceModel.Description.ServiceEndpoint arguments. I simply pass them down to the base DuplexChannelFactory class, e.g.: public DerivedDuplexChannelFactory(System.ServiceModel.InstanceContext instanceContext, System.ServiceModel.Description.ServiceEndpoint endPoint) : base(instanceContext, endPoint) {} The problem I am running into that I get timeout exceptions when trying to callback the client during a service call, e.g.: Client subscribes to Service Client calls some Service method, during which call the Service will callback to the client Before I go further, if I call down to a different base constructor of DuplexChannelFactory, things work perfectly, e.g.: public DerivedDuplexChannelFactory(System.ServiceModel.InstanceContext instanceContext, System.ServiceModel.Description.ServiceEndpoint endPoint) : base(instanceContext, endPoint.Binding, endPoint.Address) {} If I use the former, I get the following exception: "This request operation sent to http://schemas.microsoft.com/2005/12/ServiceModel/Addressing/Anonymous did not receive a reply within the configured timeout (00:00:59.9820000). The time allotted to this operation may have been a portion of a longer timeout. This may be because the service is still pr

Placing ..... configuration information in a config file other than app.config

Hi, I'm sorry if this question has been asked/answered before on this forum. I have searched both here and on the web in general, but to no avail as yet... I am running VS2010 and .Net 4, so in theory have all the latest versions of everything at my disposal. I have an executable a.exe. This downcalls into a dll b.dll. b.dll wants to send an MSMQ message using WCF. For cleanness (a.exe is a generic service and knows nothing about WCF) I want to define the client endpoint in b.dll.config. However I am finding that WCF is insisting that the information is held in a.exe.config. The exact problem is that when I create my proxy (i.e. the class which derives from ClientBase<T>), I get the message Could not find endpoint element with name 'XXX' and contract 'YYY' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element. From what I have seen I have just described an extremely common problem that people have had with WCF over the years. My questions is basically to find out, given that I have WCF 4 at my disposal, whether there is now a standard approach to this scenario? Things I have tried so far: The obvious one...putting all my config info in a.exe.config. When I do this, everything works file, so I

Exception of type 'System.ServiceModel.FaultException`1' occurred in WCF library

Hi, While Throwing Custom Fault Exception, am getting the warning message as An exception of type 'System.ServiceModel.FaultException`1' occurred in IAuthentication.DLL but was not handled in user code But Fault Exception handled in Client Side Please let me know, How Can I suppress this warning? Regards, Ganesh

System.ServiceModel.Security.SecurityNegotiationException in WCF RIA Service

Good day, I created a WCF RIA service application in Visual Studio 2008. However, when I run the application it posts this exception. I set the includeExceptionDetailInFaults to true: <behaviors> <serviceBehaviors> <behavior name="serviceBehavior"> <serviceDebug includeExceptionDetailInFaults="true"/> <serviceMetadata httpGetEnabled="true"/> </behavior> </serviceBehaviors> </behaviors> However, I still get the this error in my client app..... Any idea to diagnose the issue? or any suggestion on exception handling in WCF?? Thanks in advance!!

dispose StreamReader causes ObjectDisposedException on stream, dot net 4.0

Hi, We have some code that populates a stringbuilder from a MemoryStream, using a StreamReader's ReadToEnd() method.  Platform is dot net 4.0 on Windows 7 machine, VS2010.  Sample code: using (StreamReader reader = new StreamReader(stream, true)) { builder.Append(reader.ReadToEnd()); } At the "}" I can quickwatch the stream and it looks fine.  I know the "using" causes dispose to be called on the streamreader at this point.  Stepping past the "}", quickwatch on stream shows "threw an exception of type 'System.ObjectDisposedException'" for the capacity, length and position properties of stream.  This is all enclosed in a "using MemoryStream" block.  Exiting the outer using block, I'll get an exception "Cannot access a closed stream."  Does anyone know a workaround.  If there is a more appropriate forum to post this question please advise.  Any help is greatly appreciated.  Thank you.

MessageQueue + ObjectDisposedException + .Net 4.0

Hi,   I have implemented a dispose pattern in a class model which uses MessageQueue. My class A where all objects from class B must register to contains a Dictionary with MessageQueue objects. This works all fine. Objects from class B can be collect by GC and the dispose pattern, which let each object from class B sent a last message during disposing and so on. BUT! if the application shutdown the objects were collected in a strange order. For instance I can see in the debugger that the MessageQueue objects are disposed before the collection is disposed they contain to? And if the first MessageQueue object is disposed alle works fine (last message sent). but if the second MessageQueue object is disposed and will got to sent a last message I got the following exception:   {"Cannot access a disposed object.\r\nObject name: 'MQCacheableInfo'."}    at System.Messaging.MessageQueue.MQCacheableInfo.get_WriteHandle()    at System.Messaging.MessageQueue.StaleSafeSendMessage(MQPROPS properties, IntPtr transaction)    at System.Messaging.MessageQueue.SendInternal(Object obj, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType)    at System.Messaging.MessageQueue.Send(Object obj)    at Core.MQWriteQueue.SendMessage(XMLTelegram Telegram)    at Core.MQManager.SendTelegram


Everything with my console host and console client were working fine until I did a reboot and nothing works anymore. I am still on as the same user. Can anyone help me out with this one please. I am stuck with this one for 1.5 days now.

I am using windows xp and VS2008 in debug mode. I have tried all the run as administrator and the httpnamespacemanager for httpcfg'ing the urlacl.

   at System.ServiceModel.Channels.SharedHttpTransportManager.OnOpen()
   at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener)
   at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback)
   at System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.HttpChannelListener.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.DatagramChannelDemuxer`2.OnOuterListenerOpen(ChannelDemuxerFilter filter, IChannelListener listener, TimeSpan timeout)
   at System.ServiceModel.Channels.SingletonChannelListener`3.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)

Sudden Error: Could not load type System.ServiceModel.Activation.HttpModule - Urgent Help Please


I have a windows 7 machine with IIS 7. I was hosting WCF services on IIS normally and i had a couple of services running.
Suddenly (i honestly did not do any configuration changes on my machine) all these services stopped working. When i try to browse the .svc file i get the following error:

"Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'"

Just in case this information is helpful, all these services are running on the basicHttpBinding.

Please help!

Could not load type 'System.ServiceModel.Activation.HttpModule'


Hello everyone,

I am using VSTS 2010 + C# + .Net 4.0 + IIS 7.5 + Windows 7. When I open an svc file (in IIS manager, right click the svc file and select browse) for a WCF project in IIS, there is an error like this, any ideas what is wrong?


Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.TypeLoadException: Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of

Could not find default endpoint element that references contract IService1 in the ServiceModel clien



I am getting the above error. When I try to generate the proxy using svcutil, I get an error  as:

"There was an error importing a wsdl:binding that the wsdl:port is dependent on"..

But the proxy .cs file is generated.

The host is running perfectly and I can view the wsdl.

Can someone help me out with this ?

Also is there any example available somewhere that I can use. I tried using MSDN Virtual lab example but I am getting the same error with it too.



Akhil Jindal

ServiceModel.AddressAlreadyInUseException stopping wcf service from starting


I have a windows service that hosts two WCF services - one using HTTP on port 8731 and the other using HTTPS on port 8732.

When I start the service, it stops after about 30 seconds with the following error

Service cannot be started. System.ServiceModel.AddressAlreadyInUseException: HTTP could not register URL https://+:8732/Design_Time_Addresses/WcfServiceHost/Session/. Another application has already registered this URL with HTTP.SYS. ---> System.Net.HttpListenerException: Failed to listen on prefix 'https://+:8732/Design_Time_Addresses/WcfServiceHost/Session/' because it conflicts with an existing registration on the machine.

using "netstat -a" before and after trying to start the service indicates that there is nothing listening on port 8732.

If I change the port from 8732 to 8733 in app.config, the service starts successfully. Running netstat -a indicates that nothing is listening on port 8732.

If I change the port back to 8732, it stops working again. I would really like to understand why this happening, but am not sure where to go from here. Any help would be appreciated.


System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at ......



I have

1 - WCF Client machine

2 - ISA Server machine

3 - WCF Services machine

I need to call the WCF service which is behind the ISA firewall server. I have following WCF Service configuration..


    <binding name="TestBinding">
       <transport proxyCredentialType="Windows" />

MTOM throws ServiceModel.ProtocolException


For some reason Mtom is not working in my WCF service. I have changed both .config (server and client) to use Mtom on one of the endpoint. When I try to do anything on the service, I get the following error.

Content Type multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:4ef93280-dcd5-4795-9b4a-9db29d4baa75+id=1";start-info="text/xml" was not supported by service http://localhost/WCFapp2/Service1.svc/str.  The client and service bindings may be mismatched.

I am hosting my service with IIS 7.5

One thing I have just discovered is that if I have the client set to Text encoding then it will work even if the service is configured to use Mtom. It's like the IIS service doen't even detect that I have changed the config file even though I made sure it saved and started/stopped and recycled the App Pool plenty of times.

I can post my config files if that would help.


using objectdatasource with entity model leads to System.ObjectDisposedException


hi every body.

i my web application i used entity data model and imported some select stored procedures as functions (Add Function Import). so i used objectdatasource to call this functions and set their parameters to retrieve data. but when i run application the following exception shows:

The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ObjectDisposedException: The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

C# SerialPort System.ObjectDisposedException, safe handle has been closed in System.DLL


I have an application in which at start up I need to do a port discovery process to determine whether instruments are attached to the end of any number of PC com ports. These com ports could be Bluetooth enumerated or, using FTDI USB to serial line convertor drivers, a USB connection. At start up I determine which ports are being used for this session by interogating all the ports stored in a list. I do this by opeing the port and then using a synchronous write and read (using timeouts of 500ms). I put try and catch around the port open to capture the case where the port has been disconnected (USB) or is not currently accessible (Bluetooth) and create a list of instrument objects each of which will have its own serial port object. Before going into normal mode I close the ports. So in essence this is

foreach(string portname in portstouselist)

    if open port success

        if writeline(Instrument?) success

            if Readline success

                 add instrument found and associated port to list

       close port

Normal running operates something like a data logger so I open each of the ports to which I have an instrument connected and start an asynchronous read with an associated data received event handler and infinite time out.

It is possible that the user connections could change during the application run.

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend