question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The operation cannot be completed because the DbContext has been disposed

See original GitHub issue

I use abp 2.0.2. The exception as follow:

The operation cannot be completed because the DbContext has been disposed.
   在 System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
   在 System.Data.Entity.Internal.Linq.DbQueryProvider.System.Data.Entity.Infrastructure.IDbAsyncQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
   在 System.Data.Entity.QueryableExtensions.CountAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   在 System.Data.Entity.QueryableExtensions.CountAsync[TSource](IQueryable`1 source)
   在 ZTO.UserAnalysis.UserInformation.UserInformationAppService.<SyncDataFromOrder>d__4.MoveNext() 位置 E:\ztoSource\UserAnalysis\ZTO.UserAnalysis.Application\UserInformation\UserInformationAppService.cs:行号 45

In application method, I set UnitOfWork`s IsDisabled to true, and i call repository in the method.

My code is bellow:

 [UnitOfWork(IsDisabled = true)]
		public async Task SyncDataFromOrder(DateTime from, DateTime to)
		{
			var orderQuery = _orderRepository.GetAll().Where(i => i.CreationTime >= from && i.CreationTime <= to).OrderBy(i => i.CreationTime);
			var querySize = await orderQuery.CountAsync();

		}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:14 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
worthy7commented, Jun 20, 2018

I see. It need’s to be virtual, or injected using the interface version. I think that is what I have been missing then. Thanks @acjh!

0reactions
acjhcommented, Jun 20, 2018

Show code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - The operation cannot be completed because ...
Since this dataContext has been disposed, it is no longer valid, and .ToList() throws an exception. That is the "why it doesn't work"....
Read more >
Re: Error message: The operation cannot be completed ...
This fails because the DbContext has been disposed. ... There are several options to solve this: 1) Turn off lazy loading: The navigation...
Read more >
Because the DbContext has been disposed. #238
The operation cannot be completed because the DbContext has been disposed. Description: An unhandled exception occurred during the execution of the current web ......
Read more >
The operation cannot be completed because ...
The operation cannot be completed because the DbContext has been disposed. The operation cannot be completed because the DbContext has been disposed.
Read more >
The operation cannot be completed because ...
The DBContext was disposed when I called ProjectManager.ConvertProjects method, so when I called otherDataManager.Load , it does not work.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found