question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ExecutionEngineException thrown when mapping with IDataReader to DTO with a different datatype for a property

See original GitHub issue

From @janv8000 on November 19, 2012 8:29

An ExecutionEngineException without any useful debug information is thrown when executing the following code. This only happens with a Release build without a debugger attached. When debugging the data comes out just fine.

Versions used: Automapper NuGet version 2.2.0 .NET 4

Database schema:

CREATE TABLE [dbo].[Foo](
[Bar] [numeric](4, 0) NOT NULL,
[Baz] [nvarchar](50) NOT NULL
)

INSERT [dbo].[Foo] ([Bar], [Baz]) VALUES (CAST(0 AS Numeric(4, 0)), N'0')
INSERT [dbo].[Foo] ([Bar], [Baz]) VALUES (CAST(112 AS Numeric(4, 0)), N'112')

Code:

class Program
{
    public class Foo
    {
        public int Bar { get; set; }
        public string Baz { get; set; }
    }

    static void Main(string[] args)
    {
        //Build as release and X86 or Any CPU
        var stringBuilder = new StringBuilder();
        stringBuilder.Append("SELECT Bar , ");// Bar is actually a numeric(4,0) but declared in dto as int
        stringBuilder.Append("       Baz ");
        stringBuilder.Append("FROM   Foo");

        List<Foo> result;
        using (var connection = new SqlConnection("Server=localsqlalias;Database=AutoMapperTest;Integrated Security=True;"))
        {
            connection.Open();
            using (var sqlCommand = new SqlCommand(stringBuilder.ToString(), connection))
            {
                using (var sqlDataReader = sqlCommand.ExecuteReader())
                {
                    Mapper.CreateMap<IDataReader, IEnumerable<Foo>>();
                    result = Mapper.Map<IDataReader, IEnumerable<Foo>>((IDataReader)sqlDataReader).ToList();
                }
            }
        }

        foreach (var aResult in result)
        {
            Console.WriteLine("{0} {1}", aResult.Bar, aResult.Baz);
        }

        Console.WriteLine("Press enter to quit");
        Console.ReadLine();
    }
}

Copied from original issue: AutoMapper/AutoMapper#273

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jumas45commented, Sep 20, 2015

@jbogard Issue still exists. Is this going to be fixed in version 4.1?

0reactions
jumas45commented, Sep 20, 2015

Temporary Workaround: In my SQL whenever there is a datatype of int, long, decimal,float, double, I am casting it as a string and then I am creating an explicit .ForMember mapping for those columns. It’s painful but works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AutoMapper: Mapping between a IDataReader and DTO ...
I have a DataReader which contains the result of a stored procedure. The naming convention for the columns use underscores for spaces. I...
Read more >
ExecutionEngineException Class (System)
The exception that is thrown when there is an internal error in the execution engine of the common language runtime. This class cannot...
Read more >
SqlDataReader.cs source code in C# .NET
Int16)); DataColumn DataType = new DataColumn(SchemaTableColumn.DataType, typeof(System.Type)); DataColumn ProviderSpecificDataType = new ...
Read more >
C#, PHP, C++, iOS, MySQL, SQL, ASP.NET, Objective-C, ...
NET MVC 3, UITableView, CodeIgniter, validation, shell, API, Google Maps, ... ColdFusion, Spring Security, model, datatable, Devise, Android AsyncTask, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found