Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

updating and reading abpsetting value returns truncated string #10283


User avatar
0
daws created

.net core, angular, aspnetzero 8.8

In a manager, we read and update a serialized json from/to an abpsetting. We do this several times in a for loop over entity objects. At some point in the loop, the retrieved setting will be truncated (to a variable length), thus crashing the json parser. At the same time, in the database, the setting has been correctly set to a valid json value.

Here's our code :

The loop :

foreach (var entity in entities) 
    _myManager.UpdateEntityAsync(entity).GetAwaiter().GetResult();``

The manager :

    [UnitOfWork]
    public async Task UpdateEntityAsync(MyEntity entity)
    {
        await _myEntityRepository.UpdateAsync(entity);
        AddDateRangeToReprocess(entity.Id, new DateRange(entity.Start, entity.End));
    }
    [UnitOfWork]
    public void AddDateRangeToReprocess(short id, DateRange range)
    {
        var existingDateRanges = GetDateRangesToReprocess();

        if (existingDateRanges == null)
        {
            existingDateRanges = new Dictionary<short, List<DateRange>>();
        }

        if (!existingDateRanges.ContainsKey(id) || existingDateRanges[id] == null)
        {
            existingDateRanges.AddOrUpdateIfExist(id, new List<DateRange>());
        }

        if (!existingDateRanges[id].Any(x => x == range))
        {
            existingDateRanges[id].Add(range);
        }

        if (_tenantManager.AbpSession.TenantId.HasValue)
        {
            _settingManager.ChangeSettingForTenant(_tenantManager.AbpSession.TenantId.Value, "EntityRanges", JsonConvert.SerializeObject(existingDateRanges));
        }
    }
    [UnitOfWork]
    public Dictionary<short, List<DateRange>> GetDateRangesToReprocess()
    {
        return JsonConvert.DeserializeObject<Dictionary<short, List<DateRange>>>(_settingManager.GetSettingValue("EntityRanges"));
    }

Output example :

//Value of the setting in the database :
{"14":[{"Start":"2021-03-01T05:39:00Z","End":"2021-03-01T05:39:44Z","Duration":"00:00:44"},{"Start":"2021-03-08T16:51:45Z","End":"2021-03-08T16:52:05Z","Duration":"00:00:20"}]}

//Value of the setting when debugging in the manager (GetDateRangesToReprocess) :
{"14":[{"Start":"2021-03-01T05:39:00Z","End":"2021-03-01T05:39:44Z","Duration":"00:00:44"},{"Start":"2021-03-08T16:51:45Z","End":"2021-03-08T16:52:05Z",

There does not seem to be a specific length to which our setting is truncated.

We figured that maybe it had to do with the cache that was not invalidated properly ?


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @daws

    Is this problem reproducable ? When looking at your code, it seems fine. Could you share your project or a reproduction project with us via email ?

  • User Avatar
    0
    daws created

    Hi @ismcagdas

    We ended up creating a separate table and not using an abpsetting for this. It's faster, it's useful for other use cases and it works fine. Thank you anyway for your reply !

  • User Avatar
    0
    hra created

    I've had this same issue, with a console app that is loading the Abp modules then accessing tenant settings. I noticed that the truncation occurs every single time, only for encrypted values.

    HTH