Eastrall / EntityFrameworkCore.DataEncryption

A plugin for Microsoft.EntityFrameworkCore to add support of encrypted fields using built-in or custom encryption providers.
MIT License
329 stars 55 forks source link

object not reference at OnModelCreating Error #10

Closed mahyarmot closed 3 years ago

mahyarmot commented 4 years ago

I have followed the package installation, however, I am receiving "Object reference not set to an instance of an object" at OnModelCreating event. The version of EF Core is 3.1.1 and the inner exception is

ChangeTracker = 'this.ChangeTracker' threw an exception of type 'System.InvalidOperationException'

```
private readonly byte[] _encryptionKey = null;
    private readonly byte[] _encryptionIV = null;
    private readonly IEncryptionProvider _provider;

    public ApplicationDbContext(DbContextOptions options)
    : base(options)
    {
        this._encryptionKey = Encoding.UTF8.GetBytes("....");
        this._encryptionIV = Encoding.UTF8.GetBytes("....");
        this._provider = new AesProvider(this._encryptionKey, this._encryptionIV);
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.UseEncryption(this._provider);
    }
mahyarmot commented 4 years ago

After reviewing the existing open bug, I tried to downgrade EF core version to 3.0.0.0 but that did not solve the issue too.

ekastimo commented 4 years ago

After doing some troubleshooting,I think there is a bug in the extension method, it appears that in the process of reading the properties from entities, some properties which are not discriminators also have PropertyInfo as null, in my case, it was owned classes. ( They have some sort of ID).

image

Eastrall commented 4 years ago

Thanks for the analysis. I'll add a verification on the PropertyInfo field. But if you want, you can open a PR to add an extra verification on the PropertyInfo.

cesarsouza commented 3 years ago

I understand a PR for this issue has been merged, does it mean it has been solved?

Eastrall commented 3 years ago

Yes indeed. It has been shipped with v2.0.0. Thanks for updating this. Closing the issue.