Base solution for your next web application
Open Closed

Open DataReader exception calling GetCurrentUser #7135


User avatar
0
dev_frontrush created

Hello,

A developer on our team is getting an error about having an open data reader but it only happens in their development environment. We have a base class that inherits the AppNameAppServiceBase class and makes use of the GetCurrentUser() and GetCurrentTenant() base class methods. It seems like they are running multiple debugging instances or something similar and/or their local database configuration may be specific where either pooling isn't configured or??? The odd part is the debugger doesn't catch the exception it just silently fails with a 500 error from the inheriting ServiceNameAppService. Below is an example/similar class:

/// <summary>
/// SomeApplicationServiceBase
/// </summary>
/// <remarks>
/// Base class for services that require a tenant and an active other entity.
/// </remarks>
public abstract class RequiredEntityApplicationServiceBase : AppNameAppServiceBase
{
    // the other entity is a junction table between the AbpUsers and the other application entity
    protected readonly IRepository<UserRequiredEntity> _otherEntityRepository;

    /// <summary>
    /// Constructor
    /// </summary>
    public RequiredEntityApplicationServiceBase(IRepository<UserRequiredEntity> userRequiredEntityRepository)
    {
        this._userRequiredEntityRepository = userRequiredEntityRepository;
    }

    protected virtual RequiredEntity GetRequiredEntity()
    {
        RequiredEntity requiredEntity = null;
        
        // Fails here silently with DataReader currently open exception
        var user = this.GetCurrentUser();

        ...
        
        return requiredEntity;
    }

    public int TenantId
    {
        get
        {
            return this.GetCurrentTenant().Id;
        }
    }

    
    public int RequiredEntityId
    {
        get
        {
            return this.GetRequiredEntity().Id;
        }
    }
}

Any ideas? Should the UserManager and AbpSession be injected into the base?


1 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    Please share the 500 error message in the log.