首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >DataProtection.EntityFramework使用Postgresql引发一个扩展

DataProtection.EntityFramework使用Postgresql引发一个扩展
EN

Stack Overflow用户
提问于 2022-03-01 10:14:54
回答 1查看 228关注 0票数 0

Postgresql数据库也有同样的问题。为了管理迁移,我使用EF。当我试图向应用程序添加迁移时,我收到了这个奇怪的问题。在开始使用SQL server之前,我从未遇到过这个问题。

代码语言:javascript
运行
复制
System.Security.Cryptography.CryptographicException: An error occurred while trying to encrypt the provided data. Refer to the inner exception for more information.
     ---> Npgsql.PostgresException (0x80004005): 42P01: relation "DataProtectionKey" does not exist
       at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming)
       at Npgsql.NpgsqlDataReader.NextResult()
       at Npgsql.NpgsqlCommand.ExecuteReaderAsync(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
       at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior)
       at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
       at System.Data.Common.DbCommand.ExecuteReader()
       at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
       at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.InitializeReader(DbContext _, Boolean result)
       at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
       at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
       at Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.EntityFrameworkCoreXmlRepository`1.GetAllElements()
       at Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager.GetAllKeys()
       at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.CreateCacheableKeyRingCore(DateTimeOffset now, IKey keyJustAdded)
       at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.Microsoft.AspNetCore.DataProtection.KeyManagement.Internal.ICacheableKeyRingProvider.GetCacheableKeyRing(DateTimeOffset now)
       at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.GetCurrentKeyRingCore(DateTime utcNow, Boolean forceRefresh)
       at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.GetCurrentKeyRing()
       at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Protect(Byte[] plaintext)
      Exception data:
        Severity: ERROR
        SqlState: 42P01
        MessageText: relation "DataProtectionKey" does not exist
        Position: 22
        File: parse_relation.c
        Line: 1381
        Routine: parserOpenTable
       --- End of inner exception stack trace ---
       at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Protect(Byte[] plaintext)
       at Microsoft.AspNetCore.DataProtection.DataProtectionCommonExtensions.Protect(IDataProtector protector, String plaintext)
       at Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter`2.<>c__DisplayClass3_0`2.<SanitizeConverter>b__0(Object v)
       at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.GetValue(ColumnModification columnModification)
       at System.Linq.Enumerable.WhereSelectListIterator`2.ToList()
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
       at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.GetDataOperations(DiffContext diffContext)+MoveNext()
       at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
       at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Sort(IEnumerable`1 operations, DiffContext diffContext)
       at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.GetDifferences(IModel source, IModel target)
       at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language)
       at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
       at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
       at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
       at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
       at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)

我正在使用:

3.1.13

  • Microsoft.AspNetCore.DataProtection.EntityFramework 3.1.13

  • Npgsql.EntityFrameworkCore.PostgreSQL 3.1.11
  1. .net core 3.1
  2. EF

我的应用程序db上下文具有以下定义

代码语言:javascript
运行
复制
....
 public DbSet<DataProtectionKey> DataProtectionKeys { get; set; }
 public DbSet<DataAudit> AuditTrail { get; set; }
 public DbSet<Settings> Settings { get; set; }
 public DbSet<ApiResourceEntity> ApiResources { get; set; }
....

DbContext定义

代码语言:javascript
运行
复制
serviceCollection.AddDataProtection()
                .SetApplicationName("MyAPP")
                .PersistKeysToDbContext<ApplicationDbContext>()
                .ProtectKeysWithDpapiNG();

编辑:,我注释了这段代码,迁移已经通过,所以问题是OnModelCreating(ModelBuilder modelBuilder)方法上的代码:

代码语言:javascript
运行
复制
 foreach (var entityType in modelBuilder.Model.GetEntityTypes())
            {
                foreach (var property in entityType.GetProperties())
                {
                    var attributes = property.PropertyInfo.GetCustomAttributes(typeof(EncryptedAttribute), false);
                    if (attributes.Any())
                    {
                        property.SetValueConverter(new EncryptedConverter(_dataProtectionProvider));
                    }
                }
            }

任何想法都可能有帮助。问候

EN

回答 1

Stack Overflow用户

发布于 2022-10-25 15:09:37

首先,您需要运行Skoruba project.Identity服务器4. 4.Admin。他将开始迁徙。然后才启动Skoruba.Identity服务器4.STS.Identity!你可能在做相反的事..。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71306836

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档