Dapper error: Failed to load type 'Dapper.SqlMapper'

I am new to Dapper. I am trying to create a new project and display the local Dapper database. Unfortunately, I always get this error:

Failed to load type 'Dapper.SqlMapper' from the assembly 'Dapper, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null'

I added Dapper from NuGet (Dapper v. 1.39.0.0). This is an 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?

+6
source share
2 answers

My problem was that a namespace collision occurred. It may be a little obvious, but you will not name anything “damned” in your project.

0
source

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

  • Dapper
  • dapper

Follow these steps to resolve this issue.

  • Create a Fresh Project and do not name anything in it Dapper (case insensitive). Even if you change the name of the exit from the "dapper" object in your existing project, this can also create problems, so it’s better to create a new project! I think this has something to do with assembly or hardcoding somewhere in dapper or visual studio (not sure!).
  • Use Nuget Manager again to install Dapper.
  • Now it should work fine.
0
source

Source: https://habr.com/ru/post/984612/


All Articles