memory issues in dot net 2.1 and 2.0

moshiko museri 1 Reputation point
2020-12-07T09:36:16.01+00:00

Hi,
I'm using Asp.Net core 2.1 for a razor pages project with a polling system (interval ajax calls). I found it has 2 types of memory leaks. the first one is when a polling occurs the other is whenever a new webpage is opened. I assume it happen on every http call but I cant ensure it. different solutions on the internet advised to go back to Asp.Net core 2.0, but when I tried it, the polling calls consumed the whole cpu usage and stuck the server. if ill upgrade to asp.net version to - 3.1 will it fix my problem? is there a solution without changing asp.net version?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,129 questions
{count} votes

1 answer

Sort by: Most helpful
  1. moshiko museri 1 Reputation point
    2020-12-10T07:38:25.07+00:00
    public class Program
    {
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);
            host.Run();
        }
    
        public static IWebHost BuildWebHost(string[] args)
        {
            IConfigurationRoot config = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("hosting.json", optional: true)
                .Build();
    
            return WebHost.CreateDefaultBuilder(args)
                .UseConfiguration(config)
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseKestrel()
                .UseIISIntegration()
            .ConfigureLogging((hostingContext, logging) =>
            {
                logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                logging.AddConsole();
                logging.AddDebug();
                logging.AddFilter("Microsoft.EntityFrameworkCore.Database.Command", LogLevel.Warning);
                logging.AddFilter("Microsoft.EntityFrameworkCore", LogLevel.Warning);
            })
                .UseStartup<Startup>()
                .Build();
        }
    
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            Assembly assem = Assembly.GetEntryAssembly();
            AssemblyName assemName = assem.GetName();
            Version ver = assemName.Version;
            #region Services
            services.AddScoped<IReportService, ReportService>();
            services.AddTransient<IPermissionService, PermissionService>();
            services.AddTransient<IStatusMonitoringService, StatusMonitoringService>();
            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
            services.AddHostedService<TimedActiveDirService>();
            services.AddHostedService<PingService>();
            services.AddHostedService<TestExtenderService>();
    
            // Add language support
            services.AddLocalization(o =>
            {
                o.ResourcesPath = "Resources";
            });
    
            services.Configure<RequestLocalizationOptions>(options =>
            {
                options.DefaultRequestCulture = localizationOptions.DefaultRequestCulture;
                options.SupportedCultures = localizationOptions.SupportedCultures;
                options.SupportedUICultures = localizationOptions.SupportedUICultures;
            });
    
            // Add Kendo UI for Telerik Scheduler
            services.AddKendo();
            #endregion Services
    
            services.AddDbContext<UserContext>(options =>
                options.UseSqlite("Data Source=" + TSMModule.TSMMng.m_SQLDataBasesPath + "/user.db")); //defined in ApplicationDbContext.cs
    
            services.AddDbContext<AuxilaryContext>(options =>
            //LMS TODO, take the path from configuration
                options.UseSqlite("Data Source=" + TSMModule.TSMMng.m_SQLDataBasesPath + "/auxilary.db")); //defined in AuxilaryContext.cs
    
            // Configure Authentication
            services.AddAuthentication(options =>
            {
                options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            }).AddCookie(options =>
            {
                options.LoginPath = "/Login";
                options.AccessDeniedPath = "/Forbidden";
            });
    
            services.AddSingleton<IClaimsTransformation, ClaimsTransformer>();
    
            services.AddMvc()
                .AddViewLocalization()
                .AddDataAnnotationsLocalization(options => options.DataAnnotationLocalizerProvider = (type, factory) => new StringLocalizer<SharedResources>(factory))
                .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver())
                .AddRazorOptions(options =>
                {
                    options.PageViewLocationFormats.Add("/Pages/Shared/{0}.cshtml");
                    options.PageViewLocationFormats.Add("/Pages/DashboardPartials/{0}.cshtml");
                });
        }
    }