Open
Description
When querying to a strongly type object which uses an unsigned short (ushort) you get an arithmetic overflow if the SQL value is greater than short.MaxValue (32767).
The SQL data type is an INT (best used for ushort values)
The mapping looks to be ignoring the fact its converting to an unsigned value which should allow twice the size (65535)
Errors
"Arithmetic operation resulted in an overflow."
Error parsing column 21 (XX=65535 - Int32)
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
mika76 commentedon Jan 16, 2019
Just hit this now with uint to bigint too
Suprcode commentedon Jan 17, 2019
I fixed this by adding a custom handler for each of the unsigned types - though i think this should really be built in
mika76 commentedon Jan 18, 2019
Oooh that's clever, thanks 😄 👍
NickCraver commentedon Jan 27, 2019
Tagging this as 2.0 - I agree adding these handlers in the box in the next release seems correct on the surface. Going on the list.
ChristoWolf commentedon Oct 13, 2021
I encountered the same when trying to map (dap?) a
BIGINT
to auint
storage object property.Dapper version:
2.0.78
rukpet commentedon Jul 1, 2022
I think I found the root of the issue.
I encountered the same problem with mapping from
SmallInt
tobyte
.It is failing only with values more than 127.
I suspect method
SqlMapper.FlexibleConvertBoxedFromHeadOfStack
uses wrongOpCodes
mapping because in my case withbyte
the method usesOpCodes.Conv_Ovf_I1_Un
so it is trying to convert SQL value to type with max value = 127 whenbyte
have max value = 255 and as result we have OverflowException for values bigger that 127.I think for conversion from
SmallInt
tobyte
the method should useOpCodes.Conv_Ovf_U1
orOpCodes.Conv_Ovf_U1_Un
.I see a similar problem with other unsigned types:
UInt16
,UInt32
andUInt64
.Dapper version: 2.0.4
Stack trace:
Mapping type:
Issue DapperLib#1164
Issue DapperLib#1164
rukpet commentedon Nov 1, 2023
@mgravell, sorry for tagging, but I see this issue is stuck. There is a solution (PR #1795) for the issue. Please check PR.
Issue #1164 (#1795)