DevTrevi / DgcReader

Extensible .NET library for decoding and validating European Digital Green Certificates
Apache License 2.0
13 stars 5 forks source link

Problem with ItalianDrlBlacklistProvider and SQLite dependencies #41

Closed Rafunk closed 2 years ago

Rafunk commented 2 years ago

Ciao @DevTrevi,

I recently updated DgcReader to version 2.1.0 and I'm working out to add ItalianDrlBlacklistProvider, in order to obtain DRL blacklist.

Unfortunately, invoking VerifyForItaly the following exception occurs: _System.IO.FileNotFoundException: 'Non è stato possibile caricare il file o l'assembly 'SQLitePCLRaw.batteriesv2' o una delle relative dipendenze. Impossibile trovare il file specificato.'

This is how services are configured:

serviceCollection
    .AddLogging(builder => builder.AddNLog())
    .AddDgcReader()
    .AddItalianTrustListProvider(o =>
    {
        ...
    })
    .AddItalianRulesValidator(o =>
    {
        ...
    })
    .AddItalianDrlBlacklistProvider(o =>
    {
        o.RefreshInterval = Options.RefreshInterval;
        o.MinRefreshInterval = Options.MinRefreshInterval;
        o.BasePath = Options.BasePath;
        o.MaxFileAge = Options.MaxFileAge;
    });

The same thing happens when explicitly instancing DgcReader without using DI.

All other functions of your library work like a charm.

I'm using VS2019, targeting .NET Framework 4.7.

Where am I wrong or forgetting something?

Thanks

DevTrevi commented 2 years ago

Ciao @Rafunk , I have tested with a simple console app targeting framework 4.7 and I got some different exceptions,... it seems that Microsoft.EntityFrameworkCore.Sqlite package, and in particular its dependency SQLitePCLRaw.bundle_e_sqlite3 causes some problems when used by packages targeting .NET Framework (from 4.6.2 to 4.8), even if the package formally supports .net standard 2.0.

More interestingly, when I refer to the DgcReader.BlacklistProviders.Italy project as project reference, like in the UnitTest in the solution, the bug can not be reproduced. When referencing it as package reference instead, I get this exception:

The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception. --->  
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> 
System.Exception: Library e_sqlite3 not found

It seems that there are some bugs of the SQLitePCLRaw.bundle_e_sqlite3 and Microsoft.EntityFrameworkCore.Sqlite packages, and I found some open issues like this: https://github.com/dotnet/efcore/issues/19396

Directly adding packages Microsoft.EntityFrameworkCore.Sqlite or SQLitePCLRaw.bundle_e_sqlite3 to the console app project solved my issue in my case. If this doesn't work, can you attach a small project reproducing the issue?

Rafunk commented 2 years ago

Ciao @DevTrevi I tried to isolate the problem in a standalone console app project: in this case it works without needing to add package SQLitePCLRaw.bundle_e_sqlite3 since it's already present.

However, in my real case, things have been a little bit more complex, since my solution is composed by a Windows service console application and a couple of library assemblies, one of which references DgcReader. Therefore I had to add the aforementioned package to the main project (not directly referencing DgcReader). Moreover, I had to manually clean some other messy package references and binding redirects, and also bumped in a further SQLite/EF Core issue: dotnet/efcore#21215 (luckily, this issue was easy to overcome since it only affects debugging in VS 😅.)

Thanks