-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'Dapper.SqlMapper' does not contain a definition for 'QueryAsync' #675
Comments
Can you paste the code calling this? |
namespace Lexacom.Byzantium.Core.SqlServer // All these are in the same assembly.
public async Task<IEnumerable<HL7Control>> GetHl7ControlRecords()
{
_log.Info("Obtaining a list of required transfer service agents.");
var agentList = StatementBuilder.BuildDapperGetAllHl7ControlRecords();
return await SqlMapper.QueryAsync<HL7Control>(_db, agentList.Sql,agentList.Param);
}
...
public DapperStatement BuildDapperGetAllHl7ControlRecords()
{
return new DapperStatement("SELECT * FROM HL7Control", null);
}
...
public class DapperStatement
{
public string Sql { get; }
public dynamic Param { get; }
public DapperStatement(string sql, dynamic param)
{
Sql = sql;
Param = param;
}
}
...
namespace Lexacom.Byzantium.Client.Lexacom3.Models // This is now in a separate assembly.
public class HL7Control
{
public Guid Id { get; set; }
public string AgentName { get; set; }
public string ServiceFailureMessage { get; set; }
public bool Enabled { get; set; }
} |
A bit more info. I changed the working Query<>() to async and that breaks now: private bool TableExists(string tableName)
{
var tableExists = StatementBuilder.CheckIfTableExists(tableName);
var result=SqlMapper.QueryAsync<string>(_db, tableExists.Sql, tableExists.Param).Result;
return result.Count == 1;
} Also if I get rid of the dynamic the code fails when it tries to call the method complaining that:
So somehow it seems that QueryAsync<> has just 'gone'. |
It sounds like your library calling Dapper is compiled against a very old version of Dapper, which pre-dates these methods. Or is another library is causing an older version of Dapper to actually be loaded. Please check your output directory and look at the version of |
Ooohhkay! I know the cause. It's because HL7Control was moved into a different namespace when I moved it into another assembly. It used to be: Lexacom.Byzantium.Core.SqlServer.SqlStatements.HL7Control If I change the namespace back (but keep it in a separate assembly) QueryAsync<>() works again. I'm not sure how it worked for our unit tests anyway but..meh. |
So..it doesn't have to be in the same namespace as the code calling it but does have to be in the namespace 'path' (ie; has the same parent namespace). |
Darn. That worked for one project but not for another (in the same solution). So the saga continues :-/ |
My apologies for the spam. I have finally found the answer. It's nothing to do with the namespaces. It's to do with the project files and how they reference the new assembly. If they use 'Project Reference Include...' Dapper will fail. But if they use 'Reference Include...' they are fine. Something smells here :-/ |
I have more information. The problem is caused by the fact we have two projects in the same solution both referencing Dapper. As explained here I've been creating a sub assembly that contains Dapper code that is common to our main project and to an external project. That results in 'Class library A' - 80% of our Dapper using code and a dependency of several EXEs. If I hack 'Class library B' so that it doesn't reference Dapper (by commenting out the functionality) the problem goes away. |
We're going to address this properly with Strong-Naming in v2. Unfortunately you're in a special kind of package/reference hell that Strong-Naming was meant to address. Adding to the v2 list. |
Closing this out since the remaining issue is the strong naming combination, coming in #688. |
Check if a SqlMapper.cs file exist in the project directory somewhere embedded in a subfolder |
Thank so much @AndrueCope, I was stuck in the same problem , I just remove the Dapper library from My API and just left dapper insolate in business class library. |
We have a core assembly that has been working fine for several months. I've done some refactoring and now we can only use SqlMapper.QueryAsync<>() when the library is called from our unit test projects. When our applications call into it they get the above exception. SqlMapper.Query<> still works.
Call stack:
The text was updated successfully, but these errors were encountered: