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

c# dapper

Question

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?

Popular Answer

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.


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