akkadotnet / Akka.Persistence.Sql

Linq2Db implementation of Akka.Persistence.Sql. Common implementation for SQL Server, Sqlite, Postgres, Oracle, and MySql.
Apache License 2.0
10 stars 10 forks source link

Newer version of Akka than Akka.Persistence.Sql hides missing npgsql error #406

Closed Lemorz56 closed 1 week ago

Lemorz56 commented 1 month ago
Version Information Package Version
Akka 1.5.24
Akka.Hosting 1.5.24
Akka.DependencyInjection 1.5.24
Akka.Persistence 1.5.24
Akka.Persistence.Hosting 1.5.24
Akka.Persistence.Sql 1.5.20
Akka.Persistence.Sql.Hosting 1.5.20


Describe the bug Using a newer Akka.NET than Persistence.Sql, hides that npgsql NuGet/Assembly is missing. I'm not sure the issue lies in this library but it's the one reporting the error ones you downgrade version.

To Reproduce I've created an MRE which can be accessed here: https://github.com/Lemorz56/AkkaMRE Inside the CSPROJ file there are both the older Akka.NET NuGet's and the newer ones. Comment the older ones in and the newer ones out to switch and see the exception/error appear after first running it and see that

Expected behavior Seeing this error:

[ERROR][06-16-2024 15:34:28.027Z][Thread 0008][akka://TEST/system/akka.persistence.snapshot-store.sql] Error during [akka://TEST/system/akka.persistence.snapshot-store.sql#1872995821] initialization
Cause: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.InvalidOperationException: Cannot load assembly Npgsql
   at LinqToDB.DataProvider.PostgreSQL.NpgsqlProviderAdapter.GetInstance()
   at LinqToDB.DataProvider.PostgreSQL.PostgreSQLMappingSchema.PostgreSQL15MappingSchema..ctor()
   at LinqToDB.DataProvider.PostgreSQL.PostgreSQLDataProvider.GetMappingSchema(PostgreSQLVersion version)
   at LinqToDB.DataProvider.PostgreSQL.PostgreSQLDataProvider..ctor(String name, PostgreSQLVersion version)
   at LinqToDB.DataProvider.PostgreSQL.PostgreSQLDataProvider15..ctor()
   at System.RuntimeType.CreateInstanceOfT()
   --- End of inner exception stack trace ---
   at System.RuntimeType.CreateInstanceOfT()
   at System.Activator.CreateInstance[T]()
   at LinqToDB.Data.DataConnection.<>c__43`1.<CreateDataProvider>b__43_0()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at LinqToDB.DataProvider.PostgreSQL.PostgreSQLProviderDetector.DetectProvider(ConnectionOptions options)
   at LinqToDB.Data.DataConnection.ConfigurationInfo.<>c__DisplayClass12_0.<GetDataProvider>b__0(Func`2 d)
   at System.Linq.Enumerable.SelectListIterator`2.MoveNext()
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at LinqToDB.Data.DataConnection.ConfigurationInfo.GetDataProvider(ConnectionOptions options, Boolean isGlobal)
   at LinqToDB.Data.DataConnection.GetDataProvider(String providerName, String connectionString)
   at LinqToDB.Data.DataConnection.GetDataProviderEx(String providerName, String connectionString)
   at LinqToDB.Data.DataConnection.ConfigurationApplier.Apply(DataConnection dataConnection, ConnectionOptions options)
   at LinqToDB.Data.ConnectionOptions.LinqToDB.Common.IApplicable<LinqToDB.Data.DataConnection>.Apply(DataConnection obj)
   at LinqToDB.DataOptions.Apply(DataConnection dataConnection)
   at LinqToDB.Data.DataConnection..ctor(DataOptions options)
   at Akka.Persistence.Sql.Db.AkkaPersistenceDataConnectionFactory.<>c__DisplayClass5_0.<.ctor>b__0()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Akka.Persistence.Sql.Db.AkkaPersistenceDataConnectionFactory.GetConnection()
   at Akka.Persistence.Sql.Snapshot.ByteArraySnapshotDao.InitializeTables()
   at Akka.Persistence.Sql.Snapshot.SqlSnapshotStore.Initialize()

Actual behavior Hiding the error:

Error during [akka://TEST/system/akka.persistence.snapshot-store.sql#259451586] initialization
Failure during [akka://TEST/system/akka.persistence.journal.sql#1422930194] initialization.
Message [LoadSnapshot] from [akka://TEST/user/test-actor#2090935664] to [akka://TEST/system/akka.persistence.snapshot-store.sql#259451586] was not delivered. [1] dead letters encountered. If this is not an expected behavior then [akka://TEST/system/akka.persistence.snapshot-store.sql#259451586] may have terminated unexpectedly. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'. Message content: LoadSnapshot<pid: example, toSeqNr: 9223372036854775807, criteria: SnapshotSelectionCriteria<maxSeqNr: 9223372036854775807, maxTimestamp: 9999-12-31, minSeqNr: 0, minTimestamp: 0001-01-01>>

Environment Windows 11, dotnet 8 latest.

Additional context Since Akka.Persistence.Postgresql seems to soon be deprecated (maybe)? I tried setting up a simple project with PostgreSQL as persistence.

I'm not sure what library is "hiding" the actual error.

Arkatufus commented 1 week ago

This is a bug in Akka.NET core library, it should be fixed in the next release. In the mean time, you can fix this by explicitly referencing Akka.NET v1.5.25 or higher. Thank you for the report.