System.OutOfMemoryException asp net MVC - PullRequest
1 голос
/ 28 марта 2012

Я получаю исключение, когда код приходит к этой части:

[GridAction]
        public JsonResult _ForRisk()
        {
            var user = current.CurrentUser;            
            var applications = from c in appRepository.GetAll().PendingForRisk(user)
                                   let client = c.Clients.FirstOrDefault(t => t.MainOwner == (int)RelationType.Borrower)                                   
                                   let timing = c.Timings.Where(t => t.ApplicationID == c.ID && t.Status == (int)AppStatus.Commited).OrderByDescending(t => t.Date).Take(1).FirstOrDefault()
                                   select new ApplicationViewModelScreen
                                   {
                                       ApplicationID = c.ID,
                                       Branch = c.Branch.Name,
                                       CompanyName = client != null ? client.CompanyName : "",
                                       CompanyRegisterNr = client != null ? client.CompanyRegistrationNo : "",
                                       DecisionStatus = c.ApplicationStatus,
                                       CreateDate = c.RegistrationDate,
                                       Submissiondate = timing != null ? timing.Date : new DateTime?(),
                                       Inputer = c.User.Name + " " + c.User.Surname,
                                    FincAssignedOfficer = c.AssignedOfficerForFinanc != null ? c.AssignedOfficerForFinanc.Name + " " + c.AssignedOfficerForFinanc.Surname : "",
                                    CRMAssignedOfficer = c.AssignedOfficerForCRM != null ?  c.AssignedOfficerForCRM.Name + " " + c.AssignedOfficerForCRM.Surname : "",
                                    CRMIndustry = client.CRMIndustyCode.Description

                                   };
            var data = applications.ToList();

                return Json(new GridModel<ApplicationViewModelScreen>
                {
                    Data = data,
                    Total = data.Count()
                }, JsonRequestBehavior.AllowGet);
        }

(я использую StructureMap в качестве DI, и я вводить в контроллер)

public ApplicationController(
            IApplicationRepository _appRepository,
            IService<Application> _applicationService, 
            ITargetRepository _targetRepository, 
            IIDGenerator _idGen,
            ICurrent _current,
            IProductRepository _productRepository,
            IUserRepository _userRepository,
            IDecisionReasonRepository _decisionReason,
            IInformation _information,
            IDecisionExceptionRepository _decisionExceptionRepository,
            ITimingRepository _timingRepository,
            ITimingDecisionRepository _timingDecisionRepository)
        {
            current = _current;
            idGen = _idGen;
            appRepository = _appRepository;
            applicationService = _applicationService;
            targetRepository = _targetRepository;
            productRepository = _productRepository;
            userRepository = _userRepository;
            decisionReason = _decisionReason;
            information = _information;
            decisionExceptionRepository = _decisionExceptionRepository;
            timingRepository = _timingRepository;
            timingDecisionRepository = _timingDecisionRepository;
        }

Исключение

System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.Collections.BitArray.set_Length(Int32 value)
   at System.Data.Query.InternalTrees.VarVec.Align(VarVec other)
   at System.Data.Query.InternalTrees.NodeInfoVisitor.Visit(FilterOp op, Node n)
   at System.Data.Query.InternalTrees.FilterOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
   at System.Data.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
   at System.Data.Query.InternalTrees.NodeInfoVisitor.RecomputeNodeInfo(Node n)
   at System.Data.Query.InternalTrees.Node.InitializeNodeInfo(Command command)
   at System.Data.Query.InternalTrees.Node.GetExtendedNodeInfo(Command command)
   at System.Data.Query.InternalTrees.NodeInfoVisitor.Visit(ProjectOp op, Node n)
   at System.Data.Query.InternalTrees.ProjectOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
   at System.Data.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
   at System.Data.Query.InternalTrees.NodeInfoVisitor.RecomputeNodeInfo(Node n)
   at System.Data.Query.InternalTrees.Node.InitializeNodeInfo(Command command)
   at System.Data.Query.PlanCompiler.TransformationRulesContext.PreProcessSubTree(Node subTree)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.PlanCompiler.TransformationRules.Process(PlanCompiler compilerState, ReadOnlyCollection`1 rulesTable, Boolean& projectionPruningRequired)
   at System.Data.Query.PlanCompiler.TransformationRules.Process(PlanCompiler compilerState, TransformationRulesGroup rulesGroup)
   at System.Data.Query.PlanCompiler.PlanCompiler.Compile(List`1& providerCommands, ColumnMap& resultColumnMap, Int32& columnCount, Set`1& entitySets)
   at System.Data.EntityClient.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree)
   at System.Data.EntityClient.EntityProviderServices.CreateCommandDefinition(DbProviderFactory storeProviderFactory, DbCommandTree commandTree)
   at System.Data.EntityClient.EntityProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
   at System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree)
   at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Prepare(ObjectContext context, DbQueryCommandTree tree, Type elementType, MergeOption mergeOption, Span span, ReadOnlyCollection`1 compiledQueryParameters)
   at System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
   at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Corporate.Presentation.MVC.Controllers.ApplicationController._ForRisk() in K:\TempProjects\CorporateAPS\Corporate.Presentation.MVC\Controllers\ApplicationController.cs:line 220
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
   at System.Web.Mvc.Controller.ExecuteCore()
   at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
   at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
   at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.<EndProcessRequest>b__d()
   at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f)
   at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
        Logged on Wednesday, March 28, 2012 at 3:47:20 PM

1 Ответ

1 голос
/ 28 марта 2012

Линия:

appRepository.GetAll().PendingForRisk(user)

Загружает то, что, по-видимому, содержит много строк в память. Кроме того, следующие две строки ухудшают ситуацию:

let client = c.Clients.FirstOrDefault(t => t.MainOwner == (int)RelationType.Borrower)                                   
let timing = c.Timings.Where(t => t.ApplicationID == c.ID && t.Status == (int)AppStatus.Commited).OrderByDescending(t => t.Date).Take(1).FirstOrDefault()

Для каждого отдельного элемента appRepository вы оцениваете Clients и Timings, для которых также может быть много элементов. Предполагается, что они будут загружены ленивыми и принесут в память еще столько же объектов. Проще говоря, исключение очевидно - вы одновременно загружаете слишком много объектов в память.

К сожалению, не зная, что на самом деле appRepository (Linq-to-Sql, Entity Framework и т. Д.), Трудно дать какие-либо подсказки о том, как улучшить ваш код. Какой тип возврата appRepository.GetAll().PendingForRisk(user)?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...