dapper rainbow MissingMethodException

c# dapper dapper-rainbow

Question

Why do I get this exception? The code isn't the same but close to the 'demo' https://gist.github.com/1599013

Exception: MissingMethodException

Desc:

Method not found: 'System.Collections.Generic.IEnumerable1<System.Object> Dapper.SqlMapper.Query(System.Data.IDbConnection, System.String, System.Object, System.Data.IDbTransaction, Boolean, System.Nullable1, System.Nullable`1)'.

Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using Dapper;
using System.Data.SqlClient;
using MySql.Data.MySqlClient;

namespace daconsole2
{
    class Program
    {
        class Product
        {
            public int Id { get; set; }
            public string Name { get; set; }
            public string Description { get; set; }
            public DateTime? LastPurchase { get; set; }
        }

        // container with all the tables
        class MyDatabase : Database<MyDatabase>
        {
            public Table<Product> Products { get; set; }
        }
        //*/
        static void Main(string[] args)
        {
            var cnn = new MySqlConnection("uid=name;pwd=pw;Port=3306;database=test");
            cnn.Open();
            var db = MyDatabase.Init(cnn, commandTimeout: 2);
            //if(false)
            db.Execute(@"create table Products (
Id int primary key,
Name varchar(20),
Description TEXT,
LastPurchase datetime)");
            var productId = db.Products.Insert(new { Name = "Hello", Description = "Nothing" });
            //var db = cnn;
            Console.ReadKey();
        }
    }
}

Accepted Answer

We had this same problem, and it turned out to be that some of the projects in the solution were referencing different versions of Dapper. For example, one project used a runtime version that showed v4.0.30319 in the Properties window. Another project had a Dapper runtime version of v2.0.50727 (.NET 3.5).

As soon as I set them all to the v2.0.50727 version, this error went away.

*It should be noted that they both show File Version 1.12.0.0, so this is not a reliable way to tell them apart.




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