Dapper: Method not found: 'System.Collections.Generic.IEnumerable`1 GridReader.Read(Boolean)'

.net asp.net-mvc c#-4.0 dapper generics

Question

I'm looking to swap some EF code-first db requests for Dapper to speed up some sluggish parts of our Web site. I've only just started experimenting, and Dapper seems fine.

I've successfully converted some code to use the .Query extension. But now I'm trying .QueryMultiple, and then the .Read extensions to get each resultset.

I've tried to move the Dapper code into a new project to keep it away from my MVC project, and the .Query stuff is fine there. But when I try to access a method with .QueryMultiple, before it even hits any breakpoints in the code I'm getting the error:

Method not found: 'System.Collections.Generic.IEnumerable`1<!!0> GridReader.Read(Boolean)'.

If I move the code into the Web project it works fine.

I can't work out what I need or what's missing. Visual Studio and ReSharper seem happy. It's compiling. This is just a run-time issue. Both projects are targeting .Net 4.5, both have nuget references to Dapper. The Dapper project is set as a Win C# class library. I've looked at the source code to SqlReader.cs and it doesn't seem to have any 'using's that I don't already have. System.Collections.Generic is automatically included, I believe, and certainly doesn't seem selectable in the Add references dialogue.

I feel I'm missing something really, really obvious...

Here's the code:

        using (var conn = new SqlConnection(ConnectionString))
        {
            conn.Open();

            // TODO: Add in checks
            const string query = @"
            SELECT * FROM FileCollections WHERE Id = @fileCollectionId
            SELECT * FROM Files f WHERE FileCollection_Id = @fileCollectionId
            SELECT * FROM ExternalLinks WHERE FileCollection_Id = @fileCollectionId
            ";

            // return a GridReader
            using (var result = conn.QueryMultiple(query, new {fileCollectionId}))
            {
                var fileCollection = result.Read<FileCollection>().Single();
                var files = result.Read<File>().ToList();
                fileCollection.Files = files;
                var externalLinks = result.Read<ExternalLink>().ToList();
                fileCollection.ExternalLinks = externalLinks;
                return fileCollection;
            }
        }

Accepted Answer

I had the exact same problem. My fix was to upgrade from Dapper 1.12.1 to Dapper 1.13 through Nuget to make it work.

In my case the problem was that I hade Dapper 1.13 in one Project and Dapper 1.12.1 in another in the same solution.

Hope this help!



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why