JasperFx / marten

.NET Transactional Document DB and Event Store on PostgreSQL
https://martendb.io
MIT License
2.8k stars 441 forks source link

Static codegen requires connection string (but doesn't need it) #3421

Open grzybsonssg opened 2 days ago

grzybsonssg commented 2 days ago

When using static codegen from command line - something like ./MyApp.exe codegen write and app was built in Release configuration Marten requires that any connection string is provided. Otherwise it throws exception. And I can't understand why.

This connection string can be anything out of the blue like server=google.or.anything.you.can.think.of.com;user id=postgres;password=not_a password;database=sth;Pooling=true;Persist Security Info=true and codegen works.

With empty connection string in appsettings it throws - tested with 7.27.0

$ ./MyApp.exe codegen write
Searching 'JasperFx.CodeGeneration.Commands, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' for commands
Searching 'Weasel.CommandLine, Version=7.5.0.0, Culture=neutral, PublicKeyToken=null' for commands
Searching 'Marten.CommandLine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' for commands

[red]ERROR:[/]System.ArgumentException: Host can't be null
  at void Npgsql.NpgsqlConnectionStringBuilder.PostProcessAndValidate()
  at NpgsqlDataSourceConfiguration Npgsql.NpgsqlSlimDataSourceBuilder.PrepareConfiguration()
  at NpgsqlDataSource Npgsql.NpgsqlSlimDataSourceBuilder.Build()
  at NpgsqlDataSource Npgsql.NpgsqlDataSourceBuilder.Build()
  at NpgsqlDataSource Weasel.Postgresql.Connections.DefaultNpgsqlDataSourceFactory.<.ctor>b__2_0(string connectionString
     )
  at TValue JasperFx.Core.Cache`2.get_Item(TKey key)
  at NpgsqlDataSource Weasel.Postgresql.Connections.DefaultNpgsqlDataSourceFactory.Create(string connectionString)
  at ITenancy Marten.StoreOptions.<>c__DisplayClass129_0.<Connection>b__0()
  at void System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
  at void System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, bool useDefaultConstructor)
  at T System.Lazy`1.CreateValue()
  at ITenancy Marten.StoreOptions.get_Tenancy()
  at void Marten.StoreOptions.Validate()
  at Marten.DocumentStore..ctor(StoreOptions options)
(and so on)
jeremydmiller commented 1 day ago

Feel like we've addressed this one a couple dozen times and it still crops up. Got it. Won't make 7.28 though