AltairCA / EntityFrameworkCore.PostgreSQL.ColumnEncryption

NPGSQL Extension that supports native PostgreSql's [Raw Encryption Functions (encrypt_iv,decrypt_iv with aes-cbc/pad:pkcs)]
15 stars 3 forks source link

"Method not found" Issue with UseEncryptAttribute() Method in .NET 8 Upgrade #10

Closed srmomin closed 1 month ago

srmomin commented 2 months ago

I am currently in the process of upgrading my API from .NET 6 to .NET 8. As part of this project, we are using the AltairCA.EntityFrameworkCore.PostgreSQL.ColumnEncryption library (Version 6.0.2.3). During this upgrade process, I have updated all NuGet packages to their respective latest stable versions and upgraded all projects to target .NET 8. While trying to run the application, I encounter an error from the OnModelCreating() method when UseEncryptAttribute() method from your library is invoked.

Here is the relevant code snippet:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    base.OnModelCreating(modelBuilder);
    var password = // Code to get encryption password
    modelBuilder.HasPostgresExtension("pgcrypto");
    modelBuilder.UseEncryptAttribute(password, EncKeyLength.L128);
}

The error message I receive is as follows:

Method not found: 'System.Collections.Generic.IEnumerable`1<Microsoft.EntityFrameworkCore.Metadata.IMutableProperty> Microsoft.EntityFrameworkCore.Metadata.IMutableEntityType.GetProperties()'.

And here is the related stack trace:

AttributeExtension.UseEncryptAttribute(ModelBuilder builder, String password, EncKeyLength encKeyLength)
DirectoryDbContext.OnModelCreating(ModelBuilder modelBuilder)
ModelCustomizer.Customize(ModelBuilder modelBuilder, DbContext context)
ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, ModelDependencies modelDependencies)
ModelSource.GetModel(DbContext context, ModelCreationDependencies modelCreationDependencies, Boolean designTime)
DbContextServices.CreateModel(Boolean designTime)
DbContextServices.get_Model()
...
...
...
IntegrationTest.CreateClient(String organisationId, String clientId, String clientName, String userId)
IntegrationTest.ExecuteTest(Func`2 request)
IntegrationTest.Get(String requestUri)

The error indicates that during the call to UseEncryptAttribute, there is an attempt to use a method called GetProperties() on IMutableEntityType from EF Core which cannot be found. Any guidance or suggestions regarding this issue would be greatly appreciated. Thank you for your time and help.

srmomin commented 1 month ago

@AltairCA any update?

AltairCA commented 1 month ago

I upgraded the nuget package, please check if it's working now :)

srmomin commented 1 month ago

Thank you @AltairCA . It is working now.