Base solution for your next web application

Activities of "gekko"

Hello, we have an application using ASP.NET CORE MVC & jQuery. It is hosted on Azure AppService (Windows), and also the database is on Azure. Recently we updated from dotnet 6 to dotnet 8, with your version 13.2.0 . After we pushed the update to Azure, the application is crashing after ca. 2 days. We have to restart the Application to get it running again. From the log we can see that it cannot connect to the Host database when the issue occurs.

ERROR 2024-08-28 19:09:41,023 [19 ] .EntityFrameworkCore.Database.Connection - An error occurred using the connection to database 'Host' on server 'xxx'. WARN 2024-08-28 19:09:41,041 [19 ] Abp.BackgroundJobs.BackgroundJobManager - System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached. at Microsoft.Data.Common.ADP.ExceptionWithStackTrace(Exception e)

In the forum we found other people having same or similar problems: https://support.aspnetzero.com/QA/Questions/12096/API-Application-Crashing-Randomly https://support.aspnetzero.com/QA/Questions/12003/Site-stopped-working-after-every-1-2-days As considered in these similar issues, we already checked if all our Abp Nuget Packages are > 6.4, they are on version 9.2.2 in all projects in the solution.

Hi, thank you, I will try it that way.

Hi, I have an application build with AspnetCore + JQuery.

I want to hide a menu item if a tenant has a certain feature activated. In other words, I want to show one menu item if the feature is activated, but show another menu item if the feature is not activated.

In AppNavigationProvicer.cs I can add Menuitems with "featureDependency". If the feature is activated, the menu item is shown, otherwise not. But I want also the opposite. Is that possible?

Hi, I have the same issue. For me it works correctly on Chrome, but on Edge I can reproduce the issue. On Edge I have to refresh the page, then the updated logo is shown.

Hi @ismcagdas

sorry for the late reply.

I did now test it, and with the changes to DateTimeStyles.RoundtripKind in MyDateTimeConverter and MyNullableDateTimeConverter it works for me 👍.

Thank you

Hi, I did all the suggested modifications, but actually it does not change anything.

I tried to set a couple of breakpoints in the classes I added, but they are never hit.? The only breakpoint that hits is the initialization of the MyAbpDateTimeJsonTypeInfoResolver in Startup. In Startup.cs, the values for aspNetCoreConfiguration.InputDateTimeFormats and aspNetCoreConfiguration.OutputDateTimeFormat are both null at the moment it gets called. Is that expected?

Basically MyAbpDateTimeJsonTypeInfoResolver is the same as AbpDateTimeJsonTypeInfoResolver from aspnetboilerplate (and the other classes are almost same). So what should change with this implementation?

Hi, I tried your suggested change. Actually, if I send a change to the api, the date(s) are then of kind Utc as expected.

However, it does also change the dates format when data is fetched with a get request. With Clock.Provider = ClockProviders.Utc all dates are then formatted as Utc too. That, unfortunately breaks all the parts where we deal with dates and times in our client applications, because before the change the dates in get requests were not formatted as UTC.

If we would start from scratch this would not be a problem. But we have to deal with this all over the place, and not only in the angular app, but also in mobile apps too.

But that is not the only problem. The even bigger problem is, because we do not only have the angular app as a client, but also mobile app(s) on Appstores. From the moment we would publish the api change and with that the current behaviour, our client apps would be broken. We do not have control that all the client apps are then immediately updated. So we risk that customers app is broken, or wrong data is displayed or edited...

Is there a way to control the behavior more precisely so that it behaves as before? Sure, we can let .AddNewtonsoftJson() in Startup.cs for the moment. But we'd prefer to make it compatible with our solution without it. What I still don't get is, why the JsonDateTimeConverter does not work.

using System;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace custom.JsonConverters
{
    public class JsonDateTimeConverter : JsonConverter<DateTime>
    {
        public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            return DateTime.Parse(reader.GetString()).ToUniversalTime();
        }

        public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
        {
            writer.WriteStringValue(value.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ"));
        }
    }
}

Because I made a similar one, a JsonDoubleConverter (because with another issue with double values), and that one was actually applied.

Question

Solution: Angular + Asp.Net Core Version: 13.1.1

Issue: After upgrading from version 12.2.1 to Version 13.1.1 submitting a datetime value as UTC does not work correctly.

After you upgraded to .Net 8 , you also removed .AddNewtonsoftJson() from Startup.cs

What I do is submitting data that contains a date value explicit as UTC, here an example of Json data we want to submit:

{
    "id": 3133,
    "name": "Test mission",
	...
    "date": "2024-05-10T00:00:00.000Z",
	...
}

As you can see, the "date" value is formatted as UTC.

The c# Type of "date" is DateTime:

public DateTime Date { get; set; }

When submitting the data to the api, the date kind is now not Utc but local. I tested this:

without .AddNewtonsoftJson() in Startup.cs

var test = input.Date.Kind; // => local

but with .AddNewtonsoftJson() in Startup.cs

var test = input.Date.Kind; // => Utc

I did a simple additional test in the same CreateOrUpdate method (without .AddNewtonsoftJson() in Startup.cs)

var testDate = System.Text.Json.JsonSerializer.Deserialize<DateTime>("\"2024-05-14T00:00:00.000Z\"");
var testKind = testDate.Kind; // => Utc

From this simple test I can see that System.Text.Json can understand that this is intended as Utc date, but why is it not with the date I am sending to the api?

The problem with the new setting is, that the data saved to the database does change the time part of the date. In my case it has a value of +2 hours : 2024-05-14 02:00:00.0000000

All suggestions about this I found was to implement a custom JsonConverter for Datetime. I tried to implement one, but unfortunately it does never hit:

Converter:

using System;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace custom.JsonConverters
{
    public class JsonDateTimeConverter : JsonConverter<DateTime>
    {
        public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            return DateTime.Parse(reader.GetString()).ToUniversalTime();
        }

        public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
        {
            writer.WriteStringValue(value.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ"));
        }
    }
}

In Startup.cs :

mvcBuilder.AddJsonOptions(options =>
{
	options.JsonSerializerOptions.Converters.Add(new JsonDateTimeConverter());
});

Do you have an idea what is wrong?

Showing 1 to 8 of 8 entries