Coder Social home page Coder Social logo

Comments (10)

ismcagdas avatar ismcagdas commented on May 27, 2024

@pawelignaczak could you share your ABP version and format the code in the issue properly ?

from aspnetboilerplate.

pawelignaczak avatar pawelignaczak commented on May 27, 2024

Done

from aspnetboilerplate.

ismcagdas avatar ismcagdas commented on May 27, 2024

Thanks. Is it possible for you to prepare a sample project with this problem ?

from aspnetboilerplate.

pawelignaczak avatar pawelignaczak commented on May 27, 2024

That would be difficult as the current project is big. Basically We get an event from remote server that triggers an async request with a new UoW: _unitOfWorkManager.Begin(TransactionScopeOption.RequiresNew).
The a chain of async requests are called. My latest findigs is that the any async bolerplate repo calls like:

                var     interdto = await base.CreateAsync(input);

or
var list=_interactionsRepository.GetAllListAsync()
or
var dataReader = await command.ExecuteReaderAsync();
if i use say :
var dataReader = command.ExecuteReader();
Then it does not happen.
But i cannot avoid using:
var interdto = await base.CreateAsync(input);

from aspnetboilerplate.

pawelignaczak avatar pawelignaczak commented on May 27, 2024

In fact i randomly get below error when try to call :
var interdto = await base.CreateAsync(input);

System.InvalidOperationException: „A second operation was started on this context instance before a previous operation completed. This is usually caused by different threads concurrently using the same instance of DbContext. For more information on how to avoid threading issues with DbContext, see https://go.microsoft.com/fwlink/?linkid=2097913.”

from aspnetboilerplate.

ismcagdas avatar ismcagdas commented on May 27, 2024

Could you share your startup.cs ? Especially services.AddAbp block.

from aspnetboilerplate.

pawelignaczak avatar pawelignaczak commented on May 27, 2024

using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Castle.Facilities.Logging;
using Abp.AspNetCore;
using Abp.AspNetCore.Mvc.Antiforgery;
using Abp.Castle.Logging.Log4Net;
using AseeVT.Authentication.JwtBearer;
using AseeVT.Configuration;
using AseeVT.Identity;
using AseeVT.Web.Resources;
using Abp.AspNetCore.SignalR.Hubs;
using Abp.Dependency;
using Abp.Json;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json.Serialization;
using AseeVT.Hubs;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.Extensions.Options;
using Microsoft.AspNetCore.Identity;
using log4net;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Globalization;
using Microsoft.AspNetCore.Localization;
using AseeVT.Web.Models.AzureKeyVault;
using Azure.Identity;
using Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider;
using Microsoft.Data.SqlClient;
using System.Collections.Generic;

namespace AseeVT.Web.Startup
{
public class Startup
{
private readonly IWebHostEnvironment _hostingEnvironment;
private readonly IConfigurationRoot _appConfiguration;

    public Startup(IWebHostEnvironment env)
    {
        _hostingEnvironment = env;
        _appConfiguration = env.GetAppConfiguration();
    }

    public void ConfigureServices(IServiceCollection services)
    {
        var azureKeyVaultConfig = _appConfiguration.GetSection("AzureKeyVault").Get<AzureKeyVaultConfig>();
        
        var clientSecretCredential = new ClientSecretCredential(
                  azureKeyVaultConfig.TenantId, 
                  azureKeyVaultConfig.ClientId, 
                  azureKeyVaultConfig.ClientSecret ); 

        SqlColumnEncryptionAzureKeyVaultProvider azureKeyVaultProvider = new SqlColumnEncryptionAzureKeyVaultProvider(clientSecretCredential);
        SqlConnection.RegisterColumnEncryptionKeyStoreProviders(
            customProviders: new Dictionary<string, SqlColumnEncryptionKeyStoreProvider>(comparer: StringComparer.OrdinalIgnoreCase)
            {
                { SqlColumnEncryptionAzureKeyVaultProvider.ProviderName, azureKeyVaultProvider }
            });

        // MVC
        services.AddControllersWithViews(
                options =>
                {
                    options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
                    options.Filters.Add(new AbpAutoValidateAntiforgeryTokenAttribute());
                }
            )
            .AddRazorRuntimeCompilation()
            .AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.ContractResolver = new AbpMvcContractResolver(IocManager.Instance)
                {
                    NamingStrategy = new CamelCaseNamingStrategy()
                };
            });

        //services.ConfigureApplicationCookie(o =>
        //{
        //    o.ExpireTimeSpan = TimeSpan.FromHours(8);
        //    o.SlidingExpiration = false;
        //});

        services.AddSingleton<IPostConfigureOptions<SecurityStampValidatorOptions>, ConfigureSecurityStampValidatorOptionsService>();

        services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
        .AddCookie(options =>
        {
            options.ExpireTimeSpan = TimeSpan.FromMinutes(240);
            options.SlidingExpiration = false;
            options.AccessDeniedPath = "/Forbidden/";
        });

        IdentityRegistrar.Register(services);
        AuthConfigurer.Configure(services, _appConfiguration);

        services.AddScoped<IWebResourceManager, WebResourceManager>();

        var options = new JsonSerializerOptions
        {
            ReferenceHandler = ReferenceHandler.Preserve
        };

        services.AddSignalR(o =>
        {
            o.EnableDetailedErrors = true;

        }).AddJsonProtocol(options =>
        {
            options.PayloadSerializerOptions.ReferenceHandler = ReferenceHandler.Preserve;
        });

        // Configure Abp and Dependency Injection
        services.AddAbpWithoutCreatingServiceProvider<AseeVTWebMvcModule>(
            // Configure Log4Net logging
            options => options.IocManager.IocContainer.AddFacility<LoggingFacility>(
                f => f.UseAbpLog4Net().WithConfig(
                    _hostingEnvironment.IsDevelopment()
                        ? "log4net.config"
                        : "log4net.Production.config"
                    )
            )
        );

    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
    {
        //app.UsePathBase(new PathString("/app"));

        app.UseAbp(); // Initializes ABP framework.

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            //app.UseExceptionHandler("/Error");
        }
        else
        {
            app.UseExceptionHandler("/Error");
        }

        app.Use(async (context, next) =>
       {
           LogicalThreadContext.Properties["CorrelationId"] = context.TraceIdentifier;

           await next.Invoke();
       });

        app.UseStaticFiles();

        app.UseRouting();

        app.UseAuthentication();

        app.UseJwtTokenMiddleware();

        app.UseAuthorization();

        //app.UseSession();
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapHub<AbpCommonHub>("/signalr");
            endpoints.MapHub<AcdHub>("/signalr-acd");
            endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
            endpoints.MapControllerRoute("defaultWithArea", "{area}/{controller=Home}/{action=Index}/{id?}");
        });
    }
}

}

from aspnetboilerplate.

ismcagdas avatar ismcagdas commented on May 27, 2024

Thanks. This seems fine. Is it possible that your code has any async over sync usages ? If you are using Jetbrains Rider, you can find such usages in your code. If not, you can try to remove TransactionScopeOption.RequiresNew if there is no special reason to use it.

from aspnetboilerplate.

pawelignaczak avatar pawelignaczak commented on May 27, 2024

Well that's the point. We receive TCP events from other system and create an asyn event from it that process some actions on services. At the same time the services can be accessed from say frontend or SignalR.

from aspnetboilerplate.

ismcagdas avatar ismcagdas commented on May 27, 2024

I mean only the code in your app, not how it is called outside from your app.

from aspnetboilerplate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.