Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FatalExecutionEngineError when using struct and SqlMapper on 1.50.2 #773

Open
Freakazoid182 opened this issue May 11, 2017 · 1 comment
Open
Labels

Comments

@Freakazoid182
Copy link

Freakazoid182 commented May 11, 2017

Since updating to 1.50.2 i'm getting an error with mapping to structs using SqlMapper

FatalExecutionEngineError occurred
  HResult=-2146233082
  Message=Exception of type 'System.ExecutionEngineException' was thrown.
  InnerException: 

I was able to reproduce this is a very simple scenario in a console application:

var connection = new SqlConnection("Server=localhost;Database=TestDb;User Id=user;Password=password;");

var sql = "SELECT * FROM Dogs WHERE Id = @Id";

var result = SqlMapper.Query<Dog, SubData, Dog>(connection, sql, (dog, subdata) =>
  {
    dog.subData = subdata;
    return dog;
  }, new { Id = 1 }, splitOn: "Age");

Model definitions:

public class Dog
{
  public int Id { get; set; }
  public string Name { get; set; }
  public SubData subData { get; set; }
}

public struct SubData
{
  public int Age { get; set; }
  public int Breed { get; set; }
}

The SQL-table is just 4 columns (nothing fancy)

Id (bigint)
Name (nvarchar(50)
Age (int)
Breed (int)

I tried debugging SqlMapper.cs and found the exception is thrown in the SqlMapper.GenerateMapper method. Actually when trying to execute the Func:

((Func<TFirst, TSecond, TReturn>)map)((TFirst)deserializer(r), (TSecond)otherDeserializers[0](r));

When I remove the Breed property from the struct, it does work. So it seems to break when the struct contains more than one property.

I'm not sure how to look any further into this.
Does anyone have any idea what this could be?

Same issue on 1.50.0
1.40.0 all working fine.

@NickCraver NickCraver added the bug label May 13, 2017
@Freakazoid182
Copy link
Author

I think this relates to issue #606.

For anyone looking for a workaround: I just let SqlMapper map to a intermediate class in stead of the struct. Then manually map to the struct in the Func.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants