GenericServices icon indicating copy to clipboard operation
GenericServices copied to clipboard

System.StackOverflowException Error

Open Almircar opened this issue 11 years ago • 5 comments

greetings, I congratulate simple and powerful class library GenericServices . I am new programming. Currently I am using GenericServices in a project, but it throws this error : System.StackOverflowException in the method :

protected override void OnModelCreating ( DbModelBuilder modelBuilder ) of DbContex .

When I try to run this command:

JsonResult public GetOrderData ( dm DataManager , IListService service) { IEnumerable data = service.GetAll < ListaClientesDto > (). ToList () ;.

The DbContex has 202 tables.

The strange is that if I run this command :

        using ( var db = new AdministrativoDC ())
        {
            var service = new ListService < customers, ListaClientesDto > ( db ) ;             
            var list = service.GetAll () ToList (). ;

This is successful .

I leave thanking you in advance collaboration .

Excuse my bad English .

Almircar avatar Jun 16 '15 02:06 Almircar

Hi Almircar,

The fact that the new ListService < customers, ListaClientesDto >(db) works says it is a problem in the definition of the DTO. When using the normal ListService(db) service then GenericServices extracts the customer Entity type from the DTO. I would look at your DTO definition and check it is correct. It should be:

public class ListaClientesDto : EfGenericDto<customers, ListaClientesDto >

If that isn't the problem then can you provide the stack trace as it should give me a better idea of where the problem is.

JonPSmith avatar Jun 16 '15 09:06 JonPSmith

Hi JonP, Here I am sending sending the trace. Useful if you can send a link dropbox where this project in a zip .

I leave thanking you in advance collaboration .

IS.Administrativo.DataLayer.dll!IS.Administrativo.DataLayer.EFGeneradas.AdministrativoDC.OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder = null) Line 450 C# EntityFramework.dll!System.Data.Entity.Internal.LazyInternalContext.CreateModelBuilder() Unknown EntityFramework.dll!System.Data.Entity.Internal.LazyInternalContext.CreateModel(System.Data.Entity.Internal.LazyInternalContext internalContext = {System.Data.Entity.Internal.LazyInternalContext}) Unknown EntityFramework.dll!System.Data.Entity.Internal.RetryLazy<System.Data.Entity.Internal.LazyInternalContext,System.Data.Entity.Infrastructure.DbCompiledModel>.GetValue(System.Data.Entity.Internal.LazyInternalContext input) Unknown EntityFramework.dll!System.Data.Entity.Internal.LazyInternalContext.InitializeContext() Unknown EntityFramework.dll!System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(System.Type entityType = {Name = Inspecting the state of an object in the debuggee of type System.Type is not supported in this context. FullName = Inspecting the state of an object in the debuggee of type System.Type is not supported in this context.}) Unknown EntityFramework.dll!System.Data.Entity.Internal.Linq.InternalSet<IS.Administrativo.DataLayer.EFGeneradas.clientes>.Initialize() Unknown EntityFramework.dll!System.Data.Entity.Internal.Linq.InternalSet<IS.Administrativo.DataLayer.EFGeneradas.clientes>.AsNoTracking() Unknown EntityFramework.dll!System.Data.Entity.Infrastructure.DbQuery<IS.Administrativo.DataLayer.EFGeneradas.clientes>.AsNoTracking() Unknown GenericServices.dll!GenericServices.Core.EfGenericDtoBase<IS.Administrativo.DataLayer.EFGeneradas.clientes,IS.Administrativo.ServiceLayer.ClientesServices.ListaClientesDto>.GetDataUntracked(GenericServices.IGenericServicesDbContext context = {IS.Administrativo.DataLayer.EFGeneradas.AdministrativoDC}) Unknown GenericServices.dll!GenericServices.Core.EfGenericDtoBase<IS.Administrativo.DataLayer.EFGeneradas.clientes,IS.Administrativo.ServiceLayer.ClientesServices.ListaClientesDto>.ListQueryUntracked(GenericServices.IGenericServicesDbContext context = {IS.Administrativo.DataLayer.EFGeneradas.AdministrativoDC}) Unknown GenericServices.dll!GenericServices.Services.Concrete.ListService<IS.Administrativo.DataLayer.EFGeneradas.clientes,IS.Administrativo.ServiceLayer.ClientesServices.ListaClientesDto>.GetAll() Unknown System.Core.dll!System.Dynamic.UpdateDelegates.UpdateAndExecute1<object,object>(System.Runtime.CompilerServices.CallSite site = {System.Runtime.CompilerServices.CallSite<System.Func<System.Runtime.CompilerServices.CallSite,object,object>>}, object arg0 = {GenericServices.Services.Concrete.ListService<IS.Administrativo.DataLayer.EFGeneradas.clientes,IS.Administrativo.ServiceLayer.ClientesServices.ListaClientesDto>}) Unknown GenericServices.dll!GenericServices.Services.Concrete.ListService.GetAll<IS.Administrativo.ServiceLayer.ClientesServices.ListaClientesDto>() Unknown IS.Administrativo.WebApp.dll!IS.Administrativo.WebApp.Controllers.ClientesController.IndexListRead(GenericServices.IListService service = {GenericServices.Services.Concrete.ListService}) Line 116 C# [Lightweight Function]
System.Web.Mvc.dll!System.Web.Mvc.ActionMethodDispatcher.Execute(System.Web.Mvc.ControllerBase controller = {IS.Administrativo.WebApp.Controllers.ClientesController}, object[] parameters = {object[1]}) Unknown System.Web.Mvc.dll!System.Web.Mvc.ReflectedActionDescriptor.Execute(System.Web.Mvc.ControllerContext controllerContext = {System.Web.Mvc.ControllerContext}, System.Collections.Generic.IDictionary<string,object> parameters = Count = 1) Unknown System.Web.Mvc.dll!System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(System.Web.Mvc.ControllerContext controllerContext = {System.Web.Mvc.ControllerContext}, System.Web.Mvc.ActionDescriptor actionDescriptor = {System.Web.Mvc.ReflectedActionDescriptor}, System.Collections.Generic.IDictionary<string,object> parameters = Count = 1) Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncControllerActionInvoker.ActionInvocation.InvokeSynchronousActionMethod() Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeSynchronousActionMethod.AnonymousMethod__39(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.SimpleAsyncResult}, System.Web.Mvc.Async.AsyncControllerActionInvoker.ActionInvocation innerInvokeState = {System.Web.Mvc.Async.AsyncControllerActionInvoker.ActionInvocation}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.ActionResult,System.Web.Mvc.Async.AsyncControllerActionInvoker.ActionInvocation>.CallEndDelegate(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.SimpleAsyncResult}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase<System.Web.Mvc.ActionResult>.End() Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.End<System.Web.Mvc.ActionResult>(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.ActionResult,System.Web.Mvc.Async.AsyncControllerActionInvoker.ActionInvocation>}, object tag = {object}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.ActionResult,System.Web.Mvc.Async.AsyncControllerActionInvoker.ActionInvocation>}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.InvokeActionMethodFilterAsynchronouslyRecursive.AnonymousMethod__3d() Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.InvokeActionMethodFilterAsynchronouslyRecursive.AnonymousMethod__3f() Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeActionMethodWithFilters.AnonymousMethod__32(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.ActionResult,System.Web.Mvc.Async.AsyncControllerActionInvoker.ActionInvocation>}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.ActionExecutedContext>.CallEndDelegate(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.ActionResult,System.Web.Mvc.Async.AsyncControllerActionInvoker.ActionInvocation>}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase<System.Web.Mvc.ActionExecutedContext>.End() Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.End<System.Web.Mvc.ActionExecutedContext>(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.ActionExecutedContext>}, object tag = {object}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.ActionExecutedContext>}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction.AnonymousMethod__1c() Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction.AnonymousMethod__1e(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.ActionExecutedContext>}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult.CallEndDelegate(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.ActionExecutedContext>}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase.End() Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.End(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult}, object tag = {object}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Controller.BeginExecuteCore.AnonymousMethod__1d(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult}, System.Web.Mvc.Controller.ExecuteCoreState innerState = {System.Web.Mvc.Controller.ExecuteCoreState}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid<System.Web.Mvc.Controller.ExecuteCoreState>.CallEndDelegate(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase<System.Web.Mvc.Async.AsyncVoid>.End() Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.End<System.Web.Mvc.Async.AsyncVoid>(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid<System.Web.Mvc.Controller.ExecuteCoreState>}, object tag = {object}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.End(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid<System.Web.Mvc.Controller.ExecuteCoreState>}, object tag = {object}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Controller.EndExecuteCore(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid<System.Web.Mvc.Controller.ExecuteCoreState>}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Controller.BeginExecute.AnonymousMethod__15(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid<System.Web.Mvc.Controller.ExecuteCoreState>}, System.Web.Mvc.Controller controller = {IS.Administrativo.WebApp.Controllers.ClientesController}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid<System.Web.Mvc.Controller>.CallEndDelegate(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid<System.Web.Mvc.Controller.ExecuteCoreState>}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase<System.Web.Mvc.Async.AsyncVoid>.End() Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.End<System.Web.Mvc.Async.AsyncVoid>(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid<System.Web.Mvc.Controller>}, object tag = {object}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.End(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid<System.Web.Mvc.Controller>}, object tag = {object}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Controller.EndExecute(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid<System.Web.Mvc.Controller>}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid<System.Web.Mvc.Controller>}) Unknown System.Web.Mvc.dll!System.Web.Mvc.MvcHandler.BeginProcessRequest.AnonymousMethod__5(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid<System.Web.Mvc.Controller>}, System.Web.Mvc.MvcHandler.ProcessRequestState innerState = {System.Web.Mvc.MvcHandler.ProcessRequestState}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid<System.Web.Mvc.MvcHandler.ProcessRequestState>.CallEndDelegate(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid<System.Web.Mvc.Controller>}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase<System.Web.Mvc.Async.AsyncVoid>.End() Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.End<System.Web.Mvc.Async.AsyncVoid>(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid<System.Web.Mvc.MvcHandler.ProcessRequestState>}, object tag = {object}) Unknown System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.End(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid<System.Web.Mvc.MvcHandler.ProcessRequestState>}, object tag = {object}) Unknown System.Web.Mvc.dll!System.Web.Mvc.MvcHandler.EndProcessRequest(System.IAsyncResult asyncResult = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid<System.Web.Mvc.MvcHandler.ProcessRequestState>}) Unknown System.Web.Mvc.dll!System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(System.IAsyncResult result = {System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid<System.Web.Mvc.MvcHandler.ProcessRequestState>}) Unknown System.Web.dll!System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() Unknown System.Web.dll!System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep step = {System.Web.HttpApplication.CallHandlerExecutionStep}, ref bool completedSynchronously = false) Unknown System.Web.dll!System.Web.HttpApplication.PipelineStepManager.ResumeSteps(System.Exception error) Unknown System.Web.dll!System.Web.HttpApplication.BeginProcessRequestNotification(System.Web.HttpContext context, System.AsyncCallback cb) Unknown System.Web.dll!System.Web.HttpRuntime.ProcessRequestNotificationPrivate(System.Web.Hosting.IIS7WorkerRequest wr = {System.Web.Hosting.IIS7WorkerRequest}, System.Web.HttpContext context = {System.Web.HttpContext}) Unknown System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(System.IntPtr rootedObjectsPointer, System.IntPtr nativeRequestContext = 188479436, System.IntPtr moduleData, int flags) Unknown System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(System.IntPtr rootedObjectsPointer, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags) Unknown [Native to Managed Transition]
[Managed to Native Transition]
System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(System.IntPtr rootedObjectsPointer, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags) Unknown System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(System.IntPtr rootedObjectsPointer, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags) Unknown [AppDomain Transition]

Almircar avatar Jun 16 '15 13:06 Almircar

Hi Almircar,

Nothing obvious in the GenericServices flow above. It looks like it goes through the right parts and then fails inside Entity Framework at line 450 in OnModelCreating (first line of the trace), which is called when the DbContext if first created. Might be worth looking at what that is - for a stack overflow exception maybe you have some recursive Entity Framework reference??

I'm not sure I can help much more, but you might try the following to pin it down:

  1. Do a list of the underlying Entity class directly fro EF to check it works OK.
  2. You said that ListService < customers, ListaClientesDto > to work, but IListService does not. That is strange as at the level that it fails at GenericServices has created the ListService < customers, ListaClientesDto > version and is using that. Please run both versions in the same test harness and check that they are different.

If all else fails then I suggest you use the ListService < customers, ListaClientesDto > version. It works in exactly the same way as IListService but is just a bit harder to write when coding.

Jon Smith

JonPSmith avatar Jun 16 '15 16:06 JonPSmith

Hi Almircar,

Have you got anywhere with this problem?

Jon Smith

JonPSmith avatar Jun 20 '15 14:06 JonPSmith

Hi Jon, Indeed the problem was that he had a recursive reference in the Entity Framework, delete it and everything is working properly. Thank you very much for being pending case.

Almircar avatar Jun 22 '15 12:06 Almircar