if that were true then i would expect ToList to fix the problem as per that article, however it does not. i still get a problem.
i think the issue is more related to connection or unit of work management and it somehow being closed early.
Rick
I think I've reproduced this in a slightly different way with a different exception.
I downloaded a completely clean version of 11.2.
And adjusted the GetUsers API call in the following way.
[HttpPost]
public async Task<PagedResultDto<UserListDto>> GetUsers(GetUsersInput input)
{
var query = GetUsersFilteredQuery(input);
var userCount = await query.CountAsync();
var users = await query
.OrderBy(input.Sorting)
.PageBy(input)
.ToListAsync();
var userListDtos = ObjectMapper.Map<List<UserListDto>>(users);
await FillRoleNames(userListDtos);
var roles = _userRoleRepository.GetAll();
var test = await roles.Select(_ => new
{
Fred = _roleRepository.FirstOrDefault(_.RoleId)
}).ToListAsync();
return new PagedResultDto<UserListDto>(
userCount,
userListDtos
);
}
When you now run the vanilla solution and go to the users screen in the admin you get the following exception. It is a slightly different exception but that could be related to me using MySQL in my actual project, but in the vanilla solution I tried using MSSQL.
I also note an exception logged from the auditing (which I think is swallowed anyway) due to me running locally and the IP address being ::1
Either way I can't see why the above code shouldn't work correctly and from what I can tell it did in previous versions.
Thanks
ERROR 2022-06-23 17:11:17,525 [37 ] Mvc.ExceptionHandling.AbpExceptionFilter - There is already an open DataReader associated with this Connection which must be closed first.
System.InvalidOperationException: There is already an open DataReader associated with this Connection which must be closed first.
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command)
at Microsoft.Data.SqlClient.SqlCommand.ValidateCommand(Boolean isAsync, String method)
at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String method) at Microsoft.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior) at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject) at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable
1.Enumerator.InitializeReader(Enumerator enumerator)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func3 operation, Func
3 verifySucceeded)
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable1.Enumerator.MoveNext() at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable
1 source, Boolean& found)
at lambda_method2167(Closure , QueryContext )
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable1 source, Expression
1 predicate)
at Abp.Domain.Repositories.AbpRepositoryBase2.FirstOrDefault(TPrimaryKey id) at lambda_method2163(Closure , QueryContext , DbDataReader , ResultContext , SingleQueryResultCoordinator ) at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable
1.AsyncEnumerator.MoveNextAsync()
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable1 source, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable
1 source, CancellationToken cancellationToken)
at Inbound.Authorization.Users.UserAppService.GetUsers(GetUsersInput input) in C:\Source\Inbound-v11-2\aspnet-core\src\Inbound.Application\Authorization\Users\UserAppService.cs:line 124
at lambda_method2062(Closure , Object )
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.
Ok. Perhaps not related to that issue. I changed the AddApp() call to be false for the RemoveConventionalInterceptors and it still fails.
PS: When trying to debug AspBoilerplate I get this now and cannot load symbols. Skipping symbol server "https://symbols.nuget.org/download/symbols". This server requires a PDB Checksum, which is not present in the binary being debugged https://symbols.nuget.org/download/symbols: Symbols not found on symbol server.
I'm still trying to find the cause, but it definitely looks like the unit of work doesn't get created for some reason. Or the one it was using is closed before the repository has used it.
At a guess it is very likely related to this comment as well. https://github.com/aspnetboilerplate/aspnetboilerplate/issues/6274
My AppService is a little different here.
I do a GetAll on a simple IRepository.
I take the result and call result.Select(_ => new OutputDto { Id = _.Id FieldSomethingElse = anotherRepository.FirstOrDefault(.AnotherFieldId).MyProp });
The call to _anotherRepository is failing due to it loosing the UnitOfWork for some reason. No Hangfire jobs or anything else like this should be causing it as it is reproducible everytime on this AppService.
@ismcagdas Is there any update on this one? I've seen this multiple times as well. We can reproduce it every time on a particular AppService. This AppService was working fine in version 10, but upgrading to 11.2 and I've got this error happening randomly as well.
Done.
Thanks Rick
https://github.com/aspnetzero/aspnet-zero-core/issues/4445
aiqbal just found this. https://github.com/aspnetzero/aspnet-zero-core/issues/3991
It's coming sometime :)
+1 from me as well.
Hi Musa,
Ok I think I can see why you are not seeing the problem.
pages.CreateChildPermission(AppPermissions.Pages_Operations_My_Permission_View, L("Pages_Operations_My_Permission_View"));
This permission is likely to also be given to the account you are currently logged in as.
Can you test again with the permission looking like this.
pages.CreateChildPermission(AppPermissions.Pages_Operations_My_Permission_View, L("Pages_Operations_My_Permission_View"), multiTenancySides: MultiTenancySides.Tenant);
That way the host account you are logged in as when you create the tenant won't actually have the permission required to subscribe to that notification (even tho the tenant admin will).
Thanks Rick