Home Argument null exception using Dapper at System.Reflection.Emit.DynamicILGenerator.Emit
Reply: 0

Argument null exception using Dapper at System.Reflection.Emit.DynamicILGenerator.Emit

pwrigshihanomoronimo
1#
pwrigshihanomoronimo Published in 2017-12-07 17:08:16Z

I am using Dapper 1.50.2 to connect to MySQL database and issued very strange error in this method

public new IEnumerable<T> Query<T>(string sql, object param = null, bool buffered = true)
{
    IEnumerable<T> result = null;
    using (var connection = Database.GetConnection())
    {
        connection.Open();
        result = connection.Query<T>(sql, param, null, buffered, 500, null);
        connection.Close();
    }      
    return result.Where(x => EntityValidator.Validate(x));
}

where T was OldOrderConfirmation

public class OldOrderConfirmation : OldBaseEntity
{
    [MapToColumn("order_id")]
    public override int Id { get; set; }

    [MapToColumn("order_number")]
    public string Number { get; set; }

    [MapToColumn("user_id")]
    public int AddressId { get; set; }

    [MapToColumn("currency_code")]
    public string CurrencyCode { get; set; }

    [MapToColumn("user_po")]
    public string Name { get; set; }

    [MapToColumn("discount_value")]
    public decimal TotalDiscount { get; set; }

    [MapToColumn("order_shipping")]
    public decimal DeliveryCosts { get; set; }

    [MapToColumn("shipping_tax")]
    public decimal VATShipping { get; set; }

    [MapToColumn("order_payment")]
    public decimal Reduction { get; set; }

    [MapToColumn("payment_tax")]
    public decimal VATReduction { get; set; }

    [MapToColumn("shipping_method_id")]
    public int ShippingMethodId { get; set; }

    [MapToColumn("bemerkungen")]
    public string Comments { get; set; }

    [MapToColumn("order_date")]
    public DateTime Date { get; set; }

    [MapToColumn("adminstatus")]
    public int Status { get; set; }

    [MapToColumn("deliverydate")]
    public DateTime? DeliveryDate { get; set; }

    [MapToColumn("license_client")]
    public int Licensee { get; set; }
}

Error (ArgumentNullException: meth is null) occured at connection.Query method with the following stack trace:

at System.Reflection.Emit.DynamicILGenerator.Emit(OpCode opcode, MethodInfo meth)
at Dapper.SqlMapper.GetTypeDeserializerImpl(Type type, IDataReader reader, Int32 startBound, Int32 length, Boolean returnNullIfFirstMissing)
at Dapper.SqlMapper.TypeDeserializerCache.GetReader(IDataReader reader, Int32 startBound, Int32 length, Boolean returnNullIfFirstMissing)
at Dapper.SqlMapper.TypeDeserializerCache.GetReader(Type type, IDataReader reader, Int32 startBound, Int32 length, Boolean returnNullIfFirstMissing)
at Dapper.SqlMapper.GetTypeDeserializer(Type type, IDataReader reader, Int32 startBound, Int32 length, Boolean returnNullIfFirstMissing)
at Dapper.SqlMapper.GetDeserializer(Type type, IDataReader reader, Int32 startBound, Int32 length, Boolean returnNullIfFirstMissing)
at Dapper.SqlMapper.<QueryImpl>d__125`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType)

* No need in next lines *

After different attempts to fix it (upgrade and downgrade Dapper, changing target framework, clean/rebuild, relaunch Visual studio), I figured out that removing (and even renaming) one specific field from model fixed the error.

[MapToColumn("order_date")]
public DateTime Date { get; set; }

Maybe problem could occur due to 'Date' word as reserved in MySQL or something like this, but I had this code working on another MySQL database!

Additional info: 'order_date' column is of type DATETIME

So I ask for some explanation why this error occured or at least could occur.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.323508 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO