none
StackOverflow: when the service get the results from database and try to send to the client RRS feed

  • Question

  • I have a service that use a repository which uses entity framework to get data from the database. The respository return the rows and the service try to send the data to the proxy in theclient. In this line, I get the stackOverflow excetion. This is the message:

    System.StackOverflowException was unhandled
    Message: An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll

    The odd thing is that I have the line that produces the error in a try/catch block, and I catach ex exception "Exception" so I think that I would catch the exception.

    My code is:

    async public Task<List<MyType>> myMethodAsync(long paramID)
    {
    	try
    	{
    		return await _repository.myMethodAsync(paramID);
    	}//try
    	catch (RepositoryException ex)
    	{
    		throw new FaultException<RepositoryExceptionInfo>(ex.Info);
    	}
    	catch(StackOverflowException ex)
    	{
    		throw;
    	}
    	catch (System.Exception ex)
    	{
    		throw;
    	}
    }

    The case is  that if the repository return few rows, for example about 30, it works good.

    Saturday, December 19, 2015 12:33 PM

Answers

  • Well, I have create a simple Class as DTO and i pass the data from my POCO to my DTO and try to send and the problem is the same. It says that the socket was discard and I can't send a big amount of data.

    I  think  that perhaps I have to set some parameter to increase the max data to transfer, but I don't know which one.

    Well, I have given you what to do, which is dump EF Code First, POCO(s)  and the Repository pattern and go with DB First, DTO(s) and DAO pattern.

    I can't do any more for you than that. It's too bad that you have gotten sucked into using EF Code First with WCF.  

    Sunday, December 20, 2015 9:35 PM

All replies

  • Where is the Stack Trace and inner exception message if any? 
    Sunday, December 20, 2015 3:41 AM
  • That's the problem, I can't get the deails of the exception. Pop up a windows that has a yellow triangle as icon and a description, enumerate the possible causes of the problem and allows me to copy the exception details to the clipboard (the message is the message that I told in the first post) and the second option is to open the exception settings. Finally I can click OK or Continue button.

    So I can't access to the stack trace and the las line of code that is execute is the line that I told in the first post.

    Thanks.

    EDIT: the list that I try to send from the service to the proxy are a list of 2883 elements that are a POCO entity type as result of a query of EF. This query has the include of few properties of the same type, because are self relationship. The total elements in the dbContext are 5508 elements. So I return 2883 as elements in the result list that include antohers entities to 5508 elements.

    If don' include this properties, it works, but by the moment I don't know if the problem is that 5508 elements are too much or if the problem is include properties in the navigation properties, but how with few elements it works, I guess that the problem is the number of elements that I amtrying to return when I include them.

    If I continue I get this error details, but I don't know if is the original problem or not:

    		StackTrace	"   en System.ServiceModel.Channels.SocketConnection.ThrowIfNotOpen()\r\n   en System.ServiceModel.Channels.SocketConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)\r\n   en System.ServiceModel.Channels.DelegatingConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)\r\n   en System.ServiceModel.Channels.PreReadConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)\r\n   en System.ServiceModel.Channels.SingletonConnectionReader.SingletonInputConnectionStream.ReadCore(Byte[] buffer, Int32 offset, Int32 count)\r\n   en System.ServiceModel.Channels.SingletonConnectionReader.SingletonInputConnectionStream.Read(Byte[] buffer, Int32 offset, Int32 count)\r\n   en System.ServiceModel.Channels.MaxMessageSizeStream.Read(Byte[] buffer, Int32 offset, Int32 count)\r\n   en System.ServiceModel.Channels.SingletonConnectionReader.Close(TimeSpan timeout)\r\n   en System.ServiceModel.Channels.SingletonConnectionReader.SingletonInputConnectionStream.Close()\r\n   en System.Xml.XmlBufferReader.Close()\r\n   en System.Xml.XmlBaseReader.Close()\r\n   en System.Xml.XmlBinaryReader.Close()\r\n   en System.Xml.XmlReader.Dispose(Boolean disposing)\r\n   en System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)\r\n   en System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(Message message, Object[] parameters)\r\n   en System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc& rpc)\r\n   en System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)\r\n   en System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)\r\n   en System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass7_0`1.<CreateGenericTask>b__0(IAsyncResult asyncResult)\r\n   en System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)\r\n--- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---\r\n   en System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   en System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   en WCF.Proxy.WcfServiceProxy.<myMethodAsync>d__91.MoveNext() en M:\\software\\\\software\\\\WCF.Client\\WcfServiceProxy.cs:línea 1362"	string

    Sunday, December 20, 2015 8:18 AM
  • Using Code First, the Repository pattern,  POCO(s) and sending  the whole shooting match through WCF is nothing but trouble. I always thank my luck stars that I ignored that and just stuck with DB Frist, using DTO(s) and using the Data Access Object pattern over the years, keeping things simple.

    You need to catch the exception on the service side, log it  and include the  stack trace so you can actually see what is happening.   

    Sunday, December 20, 2015 1:00 PM
  • http://blog.sapiensworks.com/post/2012/11/01/Repository-vs-DAO.aspx/

    http://www.tutorialspoint.com/design_pattern/data_access_object_pattern.htm

    http://www.exceptionnotfound.net/entity-framework-for-beginners-creating-a-database-first-model/

    https://en.wikipedia.org/wiki/Data_transfer_object

    https://entitiestodtos.codeplex.com/

    The DTO(s) by Enity-2-DTO are data contracts to WCF. You leave the EF entities behind WCF and you send the DTO(s).

    You create a classlib project called Entities, you create the DTO(s) there, and all projects that need to use the DTO(s) set project reference to Entities.

    https://msdn.microsoft.com/en-us/library/ee658090.aspx?f=255&MSPPError=-2147217396

    Watch the whole show and then you rip out the Service Layer, make it consume the WCF service and the client consume the Service Layer.

    http://polymorphicpodcast.com/shows/mv-patterns/

    var sl = ServiceLayer.Instance;

    var orders = sl.GetOrders();

    Sunday, December 20, 2015 3:11 PM
  • Well, I have create a simple Class as DTO and i pass the data from my POCO to my DTO and try to send and the problem is the same. It says that the socket was discard and I can't send a big amount of data.

    I  think  that perhaps I have to set some parameter to increase the max data to transfer, but I don't know which one.
    Sunday, December 20, 2015 8:00 PM
  • Well, I have create a simple Class as DTO and i pass the data from my POCO to my DTO and try to send and the problem is the same. It says that the socket was discard and I can't send a big amount of data.

    I  think  that perhaps I have to set some parameter to increase the max data to transfer, but I don't know which one.

    Well, I have given you what to do, which is dump EF Code First, POCO(s)  and the Repository pattern and go with DB First, DTO(s) and DAO pattern.

    I can't do any more for you than that. It's too bad that you have gotten sucked into using EF Code First with WCF.  

    Sunday, December 20, 2015 9:35 PM