Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dapper error: Could not load type 'Dapper.SqlMapper'

Tags:

c#

dapper

I'm new in Dapper. I trying to create new project and map local database by Dapper. Unfortunately I always receive this error:

Could not load type 'Dapper.SqlMapper' from assembly 'Dapper, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'

I added Dapper by NuGet (Dapper v. 1.39.0.0). This is example of my code:

public static IEnumerable<TBMobileDetails> Allmobilelisting()
{
     SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=""c:\users\database.mdf"";Integrated Security=True");

     string query = "select * from Mobiledata";
     var result = con.Query<TBMobileDetails>(query);
     return result;
} 

Where is the problem?

like image 229
Emil Avatar asked Apr 02 '15 09:04

Emil


2 Answers

This problem occurs generally when there is an object / class / type named

  • Dapper
  • dapper

Do following steps to remove this issue

  1. Create a Fresh Project and do NOT name anything in it with Dapper (case insensitive). Even if you change name of exiting 'dapper' object in your existing project then too it might create problems so its better to create a fresh project! I think it has something to do with assembly or hardcoding somewhere in dapper or visual studio (not sure!).
  2. Use Nuget Manager again to Install Dapper.
  3. It should work fine now.
like image 69
vibs2006 Avatar answered Oct 04 '22 21:10

vibs2006


My problem was that there was a namespace collision. Maybe a little obvious, but don't name anything "dapper" in your project.

like image 41
Trevor Avatar answered Oct 04 '22 22:10

Trevor