Open Closed

Error on Elsa workflow integration #9483


0
KPCS created

Hi,

We are trying to integrate an Elsa workflow in asp.net zero application (Version 9.0.1) but Elsa dashboard is throwing following error.

Error:

Mvc.ExceptionHandling.AbpExceptionFilter - Unable to cast object of type 'Castle.Proxies.SessionAppServiceProxy' to type 'Microsoft.AspNetCore.Mvc.Controller'.
System.InvalidCastException: Unable to cast object of type 'Castle.Proxies.SessionAppServiceProxy' to type 'Microsoft.AspNetCore.Mvc.Controller'.
   at Elsa.Dashboard.ActionFilters.NotifierFilter.OnActionExecuted(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

Above error comes when we add services.AddElsaDashboard() in the startup file. Please see below code block.

Web.Host/startup/startup.cs

public IServiceProvider ConfigureServices(IServiceCollection services)
{
//MVC
services.AddControllersWithViews(options =>
{
options.Filters.Add(new AbpAutoValidateAntiforgeryTokenAttribute());
}).AddNewtonsoftJson();

services.AddSignalR();

// Elsa Workflow basic configuration
services.AddElsa();
services.AddHttpActivities(options => options.Bind(appConfiguration.GetSection("Elsa:Http")));
services.AddEmailActivities(options => options.Bind(appConfiguration.GetSection("Elsa:Smtp")));
services.AddTimerActivities(options => options.Bind(_appConfiguration.GetSection("Elsa:Timers")));

// Add services used for the workflows dashboard.
services.AddElsaDashboard();***

Please help me on this issue

Thanks,

Kind Regards, Kumar Prashant


13 Answer(s)
  • 0
    maliming created
    Support Team

    hi KPCS

    Can you use the template project to reproduce this problem and share it with me?

    https://aspnetboilerplate.com/Templates

  • 0
    KPCS created

    Hi,

    As per the above suggestion I created a sample project and integrated Elsa Workflow But same error occured.

    Sample Project link is:

    https://drive.google.com/file/d/1xC7vvPGqSFWonjgMl3m2mh7TwwdghXRe/view?usp=sharing Elsa Integration documentation link : https://docs.google.com/document/d/16UjD9yQc1zQH7md4XLh-iPgjA12q62zWw_SXGwl8hMI/edit?usp=sharing

    Thanks,

  • 0
    maliming created
    Support Team

    hi I request the access permission .

  • 0
    maliming created
    Support Team

    hi

    using System.Reflection;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.Extensions.Configuration;
    using Abp.Modules;
    using Abp.Reflection.Extensions;
    using Castle.MicroKernel.Registration;
    using ElsaProject.Configuration;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.AspNetCore.Mvc.RazorPages;
    
    namespace ElsaProject.Web.Host.Startup
    {
        [DependsOn(
           typeof(ElsaProjectWebCoreModule))]
        public class ElsaProjectWebHostModule: AbpModule
        {
            private readonly IWebHostEnvironment _env;
            private readonly IConfigurationRoot _appConfiguration;
    
            public ElsaProjectWebHostModule(IWebHostEnvironment env)
            {
                _env = env;
                _appConfiguration = env.GetAppConfiguration();
            }
    
            public override void Initialize()
            {
                IocManager.RegisterAssemblyByConvention(typeof(ElsaProjectWebHostModule).GetAssembly());
    
                Register(typeof(Elsa.Dashboard.Areas.Elsa.Controllers.HomeController).GetAssembly());
                Register(typeof(Elsa.WorkflowDesigner.ViewComponents.WorkflowDesignerViewComponent).GetAssembly());
            }
    
            private void Register(Assembly assembly)
            {
                //Controller
                IocManager.IocContainer.Register(
                    Classes.FromAssembly(assembly)
                        .BasedOn<Controller>()
                        .If(type => !type.GetTypeInfo().IsGenericTypeDefinition && !type.IsAbstract)
                        .LifestyleTransient()
                );
    
                //Razor Pages
                IocManager.IocContainer.Register(
                    Classes.FromAssembly(assembly)
                        .BasedOn<PageModel>()
                        .If(type => !type.GetTypeInfo().IsGenericTypeDefinition && !type.IsAbstract)
                        .LifestyleTransient()
                );
    
                //ViewComponents
                IocManager.IocContainer.Register(
                    Classes.FromAssembly(assembly)
                        .BasedOn<ViewComponent>()
                        .If(type => !type.GetTypeInfo().IsGenericTypeDefinition)
                        .LifestyleTransient()
                );
            }
        }
    }
    
    
    
  • 0
    KPCS created

    Hi Team,

    We have implemented the logic given by you but the castle service proxy problem still occurs while we add Elsa dashboard in a startup file.

    Please guide us or send us the sample code where ELSA dashboard is implemented.

    Thank you

  • 0
    maliming created
    Support Team

    Hi @KPCS

    https://github.com/maliming/aspnetboilerplate-elsa-workflows

  • 0
    KPCS created

    Hi Team,

    Thank you for the code. While setting up the code we have recorded following observations.

    Observation 1 : Steps :

    1. Setup database for Elsa Workflow and my project database
    2. Then I compile my application and start the IIS server.
    3. Then I redirect to localhost:21021/elsa/home and it's working fine thanks for that.
    4. When I redirect to localhost:4200 that time the pop up window comes up with an error. So for debugging that error I checked my log file.

    ERROR :

    Mvc.ExceptionHandling.AbpExceptionFilter - Unable to cast object of type 'Castle.Proxies.SessionAppServiceProxy' to type 'Microsoft.AspNetCore.Mvc.Controller'. System.InvalidCastException: Unable to cast object of type 'Castle.Proxies.SessionAppServiceProxy' to type 'Microsoft.AspNetCore.Mvc.Controller'. at Elsa.Dashboard.ActionFilters.NotifierFilter.OnActionExecuted(ActionExecutedContext context) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

    After that, I stop my IIS server and after some time start IIS server again.

    Observation 2:

    1. I redirect to localhost:21021/elsa/home it's working fine.
    2. When I redirect to localhost:4200 that time the pop up window comes up with an error. So for debugging that error I checked my log file but at this time "Castle.Proxies.SessionAppServiceProxy" error does not come. Another error come :

    ERROR 2020-08-19 21:59:47,166 [11 ] .EntityFrameworkCore.Database.Connection - An error occurred using the connection to database 'KPCSDb' on server 'localhost'. ERROR 2020-08-19 21:59:47,468 [11 ] Microsoft.EntityFrameworkCore.Query - An exception occurred while iterating over the results of a query for context type 'Elsa.Persistence.EntityFrameworkCore.DbContexts.SqlServerContext'. System.Threading.Tasks.TaskCanceledException: A task was canceled. at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnectionAsync(Boolean errorsExpected, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnectionAsync(Boolean errorsExpected, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected) at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func4 operation, Func4 verifySucceeded, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.AsyncEnumerator.MoveNextAsync() System.Threading.Tasks.TaskCanceledException: A task was canceled. at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnectionAsync(Boolean errorsExpected, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnectionAsync(Boolean errorsExpected, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected) at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func4 operation, Func4 verifySucceeded, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.AsyncEnumerator.MoveNextAsync()

    I think at the login screen application confuse about which database to use. Please let us know howcan we resolve this issue

  • 0
    maliming created
    Support Team

    hi .

    Mvc.ExceptionHandling.AbpExceptionFilter - Unable to cast object of type 'Castle.Proxies.SessionAppServiceProxy' to type 'Microsoft.AspNetCore.Mvc.Controller'.

    It seems the elsa already fix it, but not released yet.

    https://github.com/elsa-workflows/elsa-core/commit/d3032a8a7acc87e19358c97060c65da3c91ea60c

  • 0
    staffing created

    Hi Support,

    I am not able to create the elsa database. I am using the below queries. I am using the github repo https://github.com/maliming/aspnetboilerplate-elsa-workflows

    SET EF_CONNECTIONSTRING="Server=localhost; Database=elsadb; Trusted_Connection=True;" dotnet ef database update

    Could you please help me?

  • 0
    maliming created
    Support Team

    hi staffing

    These steps provided by KPCS.

  • 0
    staffing created

    Thanks, these are working.

  • 0
    KPCS created

    Hi,

    We checked on ELSA roadmap and it seems to be slow in evolving. Due to this issue "Mvc.ExceptionHandling.AbpExceptionFilter - Unable to cast object of type 'Castle.Proxies.SessionAppServiceProxy' to type 'Microsoft.AspNetCore.Mvc.Controller'." is not fixed yet on release.

    Which other workflow engine have you seen integrating effectively with ASPNetZero?

    Thnaks,

    Kind Regards, Kumar Prashant

  • 0
    maliming created
    Support Team

    hi

    elsa-core has released new version.

    https://github.com/elsa-workflows/elsa-core/releases