Tomboi88 / dapper-dot-net

Automatically exported from code.google.com/p/dapper-dot-net
Other
0 stars 0 forks source link

IL error with multi mapping child struct when first column is null #119

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
When using the multi-mapping functionality, if the column you are splitting on 
when using a child struct is null, a System.Security.VerificationException is 
thrown.  

class Owner
{
  public int Id { get; set; }
  public string Name { get; set; }
  public Car Car { get; set; }
}

struct Car
{
  public string Name { get; set; }  
  public int Age { get; set; }
}

public void TestStructsInMultiMapping()
{
  var owner = connection.Query<Owner, Car, Owner>("select 1 Id, 'Joe' Name, null Name, 21 Age, 2 Trap", splitOn: "Name", map: (o, c) =>
  {
    o.Car = c;
    return o;
  }).First();

  owner.Id.IsEqualTo(1);
  owner.Name.IsEqualTo("Joe");
  owner.Car.Name.IsEqualTo(null);
  owner.Car.Age.IsEqualTo(21);
}

Stack trace:
System.Data.DataException: Error parsing column 2 (Name=<null>) ---> 
System.Security.VerificationException: Operation could destabilize the runtime.
   at Deserialize04ddb73c-4460-4b10-8f94-9b6902b51cf1(IDataReader )
   --- End of inner exception stack trace ---
   at Dapper.SqlMapper.ThrowDataException(Exception ex, Int32 index, IDataReader reader) in c:\projects\dapper-dot-net\Dapper\SqlMapper.cs:line 2142
   at Deserialize04ddb73c-4460-4b10-8f94-9b6902b51cf1(IDataReader )
   at Dapper.SqlMapper.<>c__DisplayClass2c`6.<GenerateMapper>b__24(IDataReader r) in c:\projects\dapper-dot-net\Dapper\SqlMapper.cs:line 1022
   at Dapper.SqlMapper.<MultiMapImpl>d__19`6.MoveNext() in c:\projects\dapper-dot-net\Dapper\SqlMapper.cs:line 994
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Dapper.SqlMapper.MultiMap[TFirst,TSecond,TThird,TFourth,TFifth,TReturn](IDbConnection cnn, String sql, Object map, Object param, IDbTransaction transaction, Boolean buffered, String splitOn, Nullable`1 commandTimeout, Nullable`1 commandType) in c:\projects\dapper-dot-net\Dapper\SqlMapper.cs:line 956
   at Dapper.SqlMapper.Query[TFirst,TSecond,TReturn](IDbConnection cnn, String sql, Func`3 map, Object param, IDbTransaction transaction, Boolean buffered, String splitOn, Nullable`1 commandTimeout, Nullable`1 commandType) in c:\projects\dapper-dot-net\Dapper\SqlMapper.cs:line 867
   at SqlMapper.Tests.TestStructsInMultiMapping() in c:\projects\dapper-dot-net\Tests\Tests.cs:line 301

Original issue reported on code.google.com by brandonk...@gmail.com on 2 Oct 2012 at 3:10