rebus-org / Rebus.SqlServer

:bus: Microsoft SQL Server transport and persistence for Rebus
https://mookid.dk/category/rebus
Other
43 stars 44 forks source link

Exception with connection string in 5.x. #37

Closed donig closed 5 years ago

donig commented 5 years ago

I upgraded to Rebus 5.0.1 and all dependencies (including Castle), with Rebus.SQLServer 5.0.2 and now get an exception during bus initialization. Rolling back Rebus.SQLServer to 4.0.0 fixes the issue.

I have the following in the Rebus initialization:

.Subscriptions(s => s.StoreInSqlServer("ATSSubscriptions", "subscriptions"))

Along with a connection string named ATSSubscriptions in the app.config. This all worked fine with 4.x, but now when it starts I get the following exception on the line above:

Rebus.Injection.ResolutionException HResult=0x80131500 Message=Could not resolve Rebus.Subscriptions.ISubscriptionStorage with decorator depth 0 - registrations: Rebus.Injection.Injectionist+Handler Source=Rebus StackTrace: at Rebus.Injection.Injectionist.ResolutionContext.Get[TService]() at Rebus.Config.RebusConfigurer.<>c.b12_27(IResolutionContext c) at Rebus.Injection.Injectionist.Resolver1.InvokeResolver(IResolutionContext context) at Rebus.Injection.Injectionist.ResolutionContext.Get[TService]() at Rebus.Config.RebusConfigurer.<>c.<Start>b__12_20(IResolutionContext c) at Rebus.Injection.Injectionist.Resolver1.InvokeResolver(IResolutionContext context) at Rebus.Injection.Injectionist.ResolutionContext.Get[TService]() at Rebus.Config.RebusConfigurer.<>c.b12_21(IResolutionContext c) at Rebus.Injection.Injectionist.Resolver1.InvokeResolver(IResolutionContext context) at Rebus.Injection.Injectionist.ResolutionContext.Get[TService]() at Rebus.Config.RebusConfigurer.<>c.<Start>b__12_10(IResolutionContext c) at Rebus.Injection.Injectionist.Resolver1.InvokeResolver(IResolutionContext context) at Rebus.Injection.Injectionist.ResolutionContext.Get[TService]() at Rebus.Config.RebusConfigurer.<>c.b12_12(IResolutionContext c) at Rebus.Injection.Injectionist.Resolver`1.InvokeResolver(IResolutionContext context) at Rebus.Injection.Injectionist.ResolutionContext.Get[TService]() at Rebus.Config.RebusConfigurer.<>c__DisplayClass12_0.b25(IResolutionContext c) at Rebus.Injection.Injectionist.Resolver1.InvokeResolver(IResolutionContext context) at Rebus.Injection.Injectionist.ResolutionContext.Get[TService]() at Rebus.Config.RebusConfigurer.<>c__DisplayClass12_0.<Start>b__26(IResolutionContext c) at Rebus.Injection.Injectionist.Resolver1.InvokeResolver(IResolutionContext context) at Rebus.Injection.Injectionist.ResolutionContext.Get[TService]() at Rebus.Injection.Injectionist.Get[TService]() at Rebus.Config.RebusConfigurer.Start() at ATSPublisherService.MessageProcessor.Start() in C:\Users\donig\MessageProcessor.cs:line 53 at ATSPublisherService.Program.<>c.

b0_3(MessageProcessor msg) in C:\Users\donig\ATSPublisherService\Program.cs:line 15 at Topshelf.ServiceConfiguratorExtensions.<>c__DisplayClass2_0`1.b0(T service, HostControl control) at Topshelf.Builders.DelegateServiceBuilder`1.DelegateServiceHandle.Start(HostControl hostControl) at Topshelf.Hosts.ConsoleRunHost.Run()

Inner Exception 1: ArgumentException: Keyword not supported: 'atssubscriptions'.

mookid8000 commented 5 years ago

oh, I think it's because the first argument to StoreInSqlServer can no longer be a connection string name, it has to be a connection string... could you try and change it into something like this:

.Subscriptions(s => {
    var connectionString = ConfigurationManager.ConnectionStrings["ATSSubscriptions"]?.ConnectionString
                           ?? throw new ConfigurationErrorsException("Could not find 'ATSSubscriptions' connection string");

    s.StoreInSqlServer("ATSSubscriptions", "subscriptions");
})
donig commented 5 years ago

Ok, passing in an actual connection string works. You should change the first parameter name - it is still connectionStringOrConnectionStringName. You might want to document that as a change - using the connection string name worked in v4, but not in v5. It looks like you dropped using a connection string name in DbConnectionProvider.cs in the Oct 10 commit.

mookid8000 commented 5 years ago

I've fixed the argument name in Rebus.SqlServer 5.0.3.

Btw. the reason this was changed, is because ConfigurationManager is not available on .NET Core, so the argument name was misleading if your code would have that as the target.

For Googleability, here's what's changed: The first argument passed to 50% of the configuration methods used to be called connectionStringOrConnectionStringName – now it's connectionString.

Thanks @donig for calling my attention to this issue 😄