Skip to content

AspNetCore Startup pattern not working after v0.13.3 #256

@Dionisos94

Description

@Dionisos94

Hello,

First of all, thanks for this lib, it's very helpful !

I am using SocketMode.
I updated my version v0.13.3 to v0.14 and since then my code is not working anymore. My app was starting but the connection to Slack couldn't be made and no slack log were shown (even with UseLogger()).

To be sure it wasn't due to any of my other libs, I took your AspNetCore example and made it run. It was working fine.
I then try bit by bit to find what could be the culprit.

I transformed your example from a "Minimal Hosting" program to a "Startup" based one and then it stopped working, exactly like my app.
I found no log that could help.

Here is my change compared to your example:

I changed "Program.cs" to be:

public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            });
    }

And I added a Startup.cs

public class Startup
    {
        private readonly IConfiguration _configuration;

        public Startup(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        public void ConfigureServices(IServiceCollection services)
        {
            var slackSettings = builder.Configuration.GetSection("Slack").Get<SlackSettings>()!;

            services.AddSlackNet(c => c
                .UseApiToken(slackSettings.ApiToken) // This gets used by the API client
                .UseAppLevelToken(slackSettings.AppLevelToken) // (Optional) used for socket mode
                .UseSigningSecret(slackSettings.SigningSecret)
                .RegisterEventHandler<MessageEvent, PingDemo>()
            );
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseSlackNet(c => c
                // You can enable socket mode for testing without having to make your web app publicly accessible
                .UseSocketMode(true)
            );

            app.UseRouting();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGet("/", () => "Hello, Slack !");
            });
        }
    }

The app starts but it doesn't reply to any slack event.

Any hint ?
Unhappily my app uses this startup pattern as it's a default in my company framework.

Same issue on either Net8 or Net10.
Same issue on either v0.14 or v0.17.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions