为什么我使用NHibernate获得System.OutOfMemoryException?

时间:2013-04-23 13:12:52

标签: c# nhibernate fluent-nhibernate out-of-memory

以下是错误的详细信息:

场景:我正在迭代一个集合,其中包含一个以'byte []'作为数据类型的字段。迭代时,它是以十亿分配字节数组。我猜这可能是嫌疑人。

错误详情:

Exception of type 'System.OutOfMemoryException' was thrown.

说明: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.

异常详细信息:System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.

来源错误:

Line 257:                    forecast.IsFileUploaded = false;
Line 258:                    var forecastFiles = forecast.ForecastFiles.Where(x => x.IsDataValid);
Line 259:                    foreach (var forecastFile in forecastFiles)
Line 260:                    {
Line 261:                        forecastFile.IsDataValid = false;

源文件:......

堆栈追踪:

[OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.]
   System.Data.SqlTypes.SqlBinary.get_Value() +31
   System.Data.SqlClient.SqlDataReader.GetBytesInternal(Int32 i, Int64 dataIndex, Byte[] buffer, Int32 bufferIndex, Int32 length) +1543
   System.Data.SqlClient.SqlDataReader.GetBytes(Int32 i, Int64 dataIndex, Byte[] buffer, Int32 bufferIndex, Int32 length) +170
   NHibernate.Driver.NHybridDataReader.GetBytes(Int32 i, Int64 fieldOffset, Byte[] buffer, Int32 bufferoffset, Int32 length) +61
   NHibernate.Type.AbstractBinaryType.Get(IDataReader rs, Int32 index) +57
   NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name) +181
   NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[] names, ISessionImplementor session, Object owner) +56
   NHibernate.Type.AbstractType.Hydrate(IDataReader rs, String[] names, ISessionImplementor session, Object owner) +48
   NHibernate.Persister.Entity.AbstractEntityPersister.Hydrate(IDataReader rs, Object id, Object obj, ILoadable rootLoadable, String[][] suffixedPropertyColumns, Boolean allProperties, ISessionImplementor session) +1208
   NHibernate.Loader.Loader.LoadFromResultSet(IDataReader rs, Int32 i, Object obj, String instanceClass, EntityKey key, String rowIdAlias, LockMode lockMode, ILoadable rootPersister, ISessionImplementor session) +451
   NHibernate.Loader.Loader.InstanceNotYetLoaded(IDataReader dr, Int32 i, ILoadable persister, EntityKey key, LockMode lockMode, String rowIdAlias, EntityKey optionalObjectKey, Object optionalObject, IList hydratedObjects, ISessionImplementor session) +264
   NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[] persisters, EntityKey[] keys, Object optionalObject, EntityKey optionalObjectKey, LockMode[] lockModes, IList hydratedObjects, ISessionImplementor session) +480
   NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, LockMode[] lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey[] keys, Boolean returnProxies) +409
   NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +1287
   NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +106
   NHibernate.Loader.Loader.LoadCollection(ISessionImplementor session, Object id, IType type) +331

[GenericADOException: could not initialize a collection: [ForecastingPortal.Models.ForecastDetail.ForecastFiles#bda8eb39-99df-421e-a51d-9fcd00a72e2c][SQL: SELECT forecastfi0_.ForecastDetail_id as Forecast5_1_, forecastfi0_.Id as Id1_, forecastfi0_.Id as Id116_0_, forecastfi0_.[Data] as Data2_116_0_, forecastfi0_.IsDataValid as IsDataVa3_116_0_, forecastfi0_.FileContent_id as FileCont4_116_0_ FROM [PATH_ForecastFileData] forecastfi0_ WHERE forecastfi0_.ForecastDetail_id=?]]
   NHibernate.Loader.Loader.LoadCollection(ISessionImplementor session, Object id, IType type) +494
   NHibernate.Loader.Collection.CollectionLoader.Initialize(Object id, ISessionImplementor session) +73
   NHibernate.Persister.Collection.AbstractCollectionPersister.Initialize(Object key, ISessionImplementor session) +58
   NHibernate.Event.Default.DefaultInitializeCollectionEventListener.OnInitializeCollection(InitializeCollectionEvent event) +628
   NHibernate.Impl.SessionImpl.InitializeCollection(IPersistentCollection collection, Boolean writing) +233
   NHibernate.Collection.AbstractPersistentCollection.Initialize(Boolean writing) +125
   NHibernate.Collection.AbstractPersistentCollection.Read() +31
   NHibernate.Collection.Generic.PersistentGenericBag`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +31
   System.Linq.WhereEnumerableIterator`1.MoveNext() +72
   ForecastingPortal.ModelHelpers.InvalidateForecastDataForVaccine(VaccineDetail vaccineDetail, ISession session) in C:\Project\Path_Performance\Source\ForecastingPortal\Helpers\ModelHelpers.cs:259
   ForecastingPortal.Web.Setup.Controllers.EnvironmentElementDefinitionController.UpdateElementDetail(FormCollection form, Guid id) in C:\Project\Path_Performance\Source\ForecastingPortal.Web\Areas\Setup\Controllers\EnvironmentSetup\EnvironmentElementDefinitionController.cs:112
   lambda_method(ExecutionScope , ControllerBase , Object[] ) +220
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +178
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +24
   Autofac.Integration.Web.Mvc.ExtensibleActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +42
   System.Web.Mvc.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() +52
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +254
   System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +254
   System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +254
   System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +254
   System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +254
   System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +192
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +314
   System.Web.Mvc.Controller.ExecuteCore() +105
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +39
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +34
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +59
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +44
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +7
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8699438
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

0 个答案:

没有答案