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


17 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

  • 0
    KPCS created

    Hi,

    While integrating elsa in ASPNetZero we are getting an error. We are using following steps to setup ESLA. Please help us on solving this issue.

    Steps :

    1. Added the latest Elsa package on the Web.Host Elsa Elsa.Dashboard Elsa.Persistence.EntityFrameworkCore

    2. Added Elsa home controller call in a KPCSWebHostModule 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&lt;PageModel&gt;()
       		.If(type => !type.GetTypeInfo().IsGenericTypeDefinition && !type.IsAbstract)
       		.LifestyleTransient()
       );
      
       //ViewComponents
       IocManager.IocContainer.Register(
       	Classes.FromAssembly(assembly)
       		.BasedOn&lt;ViewComponent&gt;()
       		.If(type => !type.GetTypeInfo().IsGenericTypeDefinition)
       		.LifestyleTransient()
       );
      

      }

    3. Database call in a startup file

      services // Add services used for the workflows runtime. .AddElsa(elsa => elsa.AddEntityFrameworkStores<SqlServerContext>(options => options.UseSqlServer(@"Server=localhost;Database=SampleElsaDb;User=sa;Password=Local;")))

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

    4: Error

    ERROR 2020-11-04 17:53:20,889 [13 ] Mvc.ExceptionHandling.AbpExceptionFilter - Method not found: 'System.__Canon AutoMapper.IMapper.Map(System.Object)'. System.MissingMethodException: Method not found: 'System.__Canon AutoMapper.IMapper.Map(System.Object)'. at Abp.AutoMapper.AutoMapperObjectMapper.Map[TDestination](Object source) at KPCS.Sessions.SessionAppService.GetCurrentLoginInformations() in F:\ESOP\src\RuleEngine\KPCS\KPCS\src\KPCS.Application\Sessions\SessionAppService.cs:line 74 at lambda_method(Closure , Object ) at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult() at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.

  • 0
    maliming created
    Support Team

    hi @KPCS

    Could you share your project to me? liming.ma@volosoft.com

  • 0
    rajalla created

    Hi,

    I am planning to integrate Elsa into our app as well. Were you able to do the integration?

    Thanks, Raj.

  • 0
    maliming created
    Support Team

    hi @Raj

    I successfully integrated it, you can check the discussion above.

    if you got a problem, you can create a new question, I will try to help you. : )