简体   繁体   中英

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

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM