You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Umbraco 10.3.1异常:已添加相同键1056(ArgumentException)

Umbraco 10.3.1 出现ArgumentException: 重复键1056的解决思路

问题场景

使用Umbraco 10.3.1开发应用,原本运行正常。生成现有数据库备份脚本并连接新数据库后触发以下异常,切回原数据库后异常依旧。

异常堆栈信息

ArgumentException: An item with the same key has already been added. Key: 1056
System.Collections.Generic.Dictionary<TKey, TValue>.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
System.Linq.Enumerable.ToDictionary<TSource, TKey>(List<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.ContentTypeCommonRepository.MapHistoryCleanup(Dictionary<int, IContentTypeComposition> contentTypes)
Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.ContentTypeCommonRepository.GetAllTypesInternal()
Umbraco.Extensions.AppCacheExtensions+<>c__DisplayClass0_0<T>.<GetCacheItem>b__0()
Umbraco.Cms.Core.Cache.SafeLazy+<>c__DisplayClass1_0.<GetSafeLazy>b__0()
Umbraco.Cms.Core.Cache.ObjectCacheAppCache.Get(string key, Func<object> factory, Nullable<TimeSpan> timeout, bool isSliding, string[] dependentFiles)...
SixLabors.ImageSharp.Web.Middleware.ImageSharpMiddleware.Invoke(HttpContext httpContext, bool retry)
StackExchange.Profiling.MiniProfilerMiddleware.Invoke(HttpContext context) in MiniProfilerMiddleware.cs
Umbraco.Cms.Web.Common.Middleware.UmbracoRequestMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
Umbraco.Cms.Web.Common.Middleware.UmbracoRequestMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)

问题分析

从堆栈追踪可以看出,错误发生在ContentTypeCommonRepository.MapHistoryCleanup方法中——尝试将历史清理数据转换为Dictionary时,发现键1056重复。这大概率是两种情况:

  1. 数据库中ID为1056的内容类型(或其版本记录)存在重复条目;
  2. Umbraco的本地缓存未刷新,即使切回原数据库,缓存里的脏数据仍在生效。

解决步骤

1. 强制清理Umbraco本地缓存

  • 停止站点服务;
  • 删除站点根目录下umbraco/Data/TEMP文件夹内的所有文件及子文件夹;
  • 重启站点,让Umbraco重新生成干净的缓存。

2. 检查并清理数据库中的重复记录

先备份数据库,再执行以下操作:

  • 查询umbracoContentType表,确认ID=1056的记录是否重复:
    SELECT * FROM umbracoContentType WHERE id = 1056
    
    如果发现多条记录,删除多余的(保留一条有效记录即可)。
  • 接着查询umbracoContentTypeVersion表,检查对应ID的版本记录是否重复:
    SELECT * FROM umbracoContentTypeVersion WHERE contentTypeId = 1056
    
    清理重复的版本条目。

3. 同步数据库结构

运行Umbraco数据库更新命令,确保数据库结构与当前代码版本一致:

dotnet umbraco database update

该命令会自动执行缺失的数据库迁移脚本,修复可能存在的结构不一致问题。

4. 验证并修复内容类型配置

  • 登录Umbraco后台,进入「设置」→「文档类型」;
  • 找到ID为1056的文档类型(可通过数据库查询umbracoContentType表的name字段快速定位);
  • 检查其配置(如组成部分、属性)是否存在异常,保存一次该文档类型,触发系统重新同步数据。

内容的提问来源于stack exchange,提问作者shashidhar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 23:10:22