Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix : 'IDataProtectionBuilder' does not contain a definition for 'PersistKeysToDbContext' and no accessible extension

I am attempting to persist Keys to SQL using the PersistKeysToDbContext extension from services.AddDataProtection(). At the moment we are using PersistKeysToStackExchangeRedis which works really well, however a need was identitied to move it to DB instead.

We are using a .net Core 2.2 project having added the following references:

Microsoft.AspNetCore.DataProtection.EntityFrameworkCore (2.2.0) Microsoft.AspNetCore.DataProtection.Extensions (2.2.0) Microsoft.AspNetCore.DataProtection.StackExchangeRedis (2.2.0) (obviously for current functionality)

Microsoft.EntityFrameworkCore (2.2.0)

services.AddDataProtection().PersistKeysToDbContext<ApplicationDbContext>();

I get the following error from the compiler:

'IDataProtectionBuilder' does not contain a definition for 'PersistKeysToDbContext' and no accessible extension method 'PersistKeysToDbContext' accepting a first argument of type 'IDataProtectionBuilder' could be found (are you missing a using directive or an assembly reference?)

like image 857
Tinus Avatar asked Sep 02 '25 14:09

Tinus


1 Answers

1) Make sure you have Microsoft.AspNetCore.DataProtection.Extensions + Microsoft.AspNetCore.DataProtection.EntityFrameworkCore installed (as references).

2) Add using Microsoft.AspNetCore.DataProtection; to Startup.cs (or wherever you have the problem).

I've tested and it works, so if it still doesn't work, you probably need to make sure you haven't missed anything.

like image 119
carl-johan.blomqvist Avatar answered Sep 05 '25 03:09

carl-johan.blomqvist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!