© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4mo ago•
21 replies
Dachi

Dapper to c# decimal conversion fail

When executing script where I retrieve properties, one of them being Price, it throws error:
System.InvalidCastException: Unable to cast object of type 'System.Decimal' to type 'System.Double'.
delivery-connector-worker | at Deserializec435cf3c-5d1c-45f9-9ce4-096c88b38636(DbDataReader)
delivery-connector-worker | --- End of inner exception stack trace ---
delivery-connector-worker | at Dapper.SqlMapper.ThrowDataException(Exception ex, Int32 index, IDataReader reader, Object value) in /_/Dapper/SqlMapper.cs:line 3966
delivery-connector-worker | at Deserializec435cf3c-5d1c-45f9-9ce4-096c88b38636(DbDataReader)
delivery-connector-worker | at Dapper.SqlMapper.QueryAsync[T](IDbConnection cnn, Type effectiveType, CommandDefinition command)
delivery-connector-worker | at Trony.DeliveryConnector.Infrastructure.Data.DapperProductRepository.<>cDisplayClass7_0.<<GetActiveProductsAsync>b0>d.MoveNext().


The weird part is that Price in c# is of a type decimal. I don't have properties that are marked as double.

This is product class that it has to match
public class Product
{
    public string VenueId { get; set; }
    public string Id { get; set; }
    public decimal Price { get; set; }
    public decimal? DiscountedPrice { get; set; }
    public bool? Enabled { get; set; }
    public DateTime? DisabledUntil { get; set; }
    public bool? InStock { get; set; }
}
public class Product
{
    public string VenueId { get; set; }
    public string Id { get; set; }
    public decimal Price { get; set; }
    public decimal? DiscountedPrice { get; set; }
    public bool? Enabled { get; set; }
    public DateTime? DisabledUntil { get; set; }
    public bool? InStock { get; set; }
}


Does anybody know why it happens?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Need Python to C Sharp Conversion
C#CC# / help
4y ago
❔ C# Database Query Optimization [Dapper & ReactJS]
C#CC# / help
3y ago
❔ Dapper
C#CC# / help
3y ago
Something getting lost in C# to VB.net conversion
C#CC# / help
2y ago