aspnetboilerplate/aspnetboilerplate · error · ArgumentException
' ' is a key field and cannot be marked readonly.
Error message
'{0}' is a key field and cannot be marked readonly. What it means
Guard in MemberMap.ReadOnly(): the member {0} has a KeyType other than NotAKey and SlapperIdentifierKey, i.e. it is an active key field. Marking a key read-only would prevent the mapper from writing key values during insert/update, so the fluent ReadOnly() call is rejected with this ArgumentException.
Solutions
- Do not call ReadOnly() on a key member; apply ReadOnly() only to non-key properties.
- Move the key mapping to a writable property and keep {0} read-only if it must not be persisted.
- Skip the ReadOnly() call for key members and control write behavior at the database/key-generation level instead.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/Abp.Dapper/Dapper-Extensions/Mapper/MemberMap.cs:197 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of aspnetboilerplate/aspnetboilerplate@2323c13a15 (2026-09-08).
Data as JSON: /api/errors/562be5b19855ccd3.
Report an issue: GitHub.
Appendix: source
Thrown at src/Abp.Dapper/Dapper-Extensions/Mapper/MemberMap.cs:197
public MemberMap Ignore()
{
if (KeyType != KeyType.NotAKey && KeyType != KeyType.SlapperIdentifierKey)
{
throw new ArgumentException(string.Format("'{0}' is a key field and cannot be ignored.", Name));
}
Ignored = true;
return this;
}
/// <summary>
/// Fluently sets the read-only status of the property.
/// </summary>
public MemberMap ReadOnly()
{
if (KeyType != KeyType.NotAKey && KeyType != KeyType.SlapperIdentifierKey)
{
throw new ArgumentException(string.Format("'{0}' is a key field and cannot be marked readonly.", Name));
}
IsReadOnly = true;
return this;
}
/// <summary>
/// Fluently sets the field length of the property
/// </summary>
/// <param name="size">The length of the field as it exists in the database</param>
public MemberMap Size(int size)
{
if (size < 0)
{
throw new ArgumentException(string.Format("'{0}' cannot have a negative field length.", Name));
}
DbSize = size;View on GitHub (pinned to 2323c13a15)