【问题标题】:C# .NET 4.5 ExecuteReaderAsync not found未找到 C# .NET 4.5 ExecuteReaderAsync
【发布时间】:2014-02-07 16:02:27
【问题描述】:

我正在尝试使用 ExecuteReaderAsync() 异步查询数据库,但出现以下错误:

'System.Data.SqlClient.SqlCommand' does not contain a definition for 
'ExecuteReaderAsync' and no extension method 'ExecuteReaderAsync' accepting a first
argument of type 'System.Data.SqlClient.SqlCommand' could be found (are you missing a 
using directive or an assembly reference?)

我正在为 Windows 桌面使用 VSE 2012,并且肯定安装了 .NET 4.5。我正在参考

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Data.dll

我读过 .NET 4.5 只是替换了 4.0,但是每当我尝试选择 4.5 目录中的 System.Data.dll 时,它都会引用 4.0 中的那个。不确定这是否重要。

【问题讨论】:

  • 如果您的项目在 .NET 4.5 上,我测试过它可以工作。您对 .NET 4 使用了错误的 DLL。如果我将项目更改为 .NET 4.0,我会遇到与您相同的异常。

标签: c# .net assemblies


【解决方案1】:

不确定这是否重要。

ExecuteReaderAsync在 4.5 中添加的,我认为确实如此!

  1. 确保您的项目在其项目设置中设置为使用 .NET 4.5。

  2. 在添加 4.5 参考之前,请确保您删除了所有早期参考。

【讨论】:

  • 耶。我在 VS 2010 中开始了这个项目,忘记更改我的设置...非常感谢!
【解决方案2】:

选择项目属性并将目标框架设置为 .NET Framework 4.5 而不是客户端配置文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-17
    • 2019-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-14
    • 1970-01-01
    相关资源
    最近更新 更多