【问题标题】:Method not found: 'System.Threading.Tasks.Task` System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync找不到方法:'System.Threading.Tasks.Task` System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync
【发布时间】:2018-04-30 17:03:58
【问题描述】:

我使用 Visual Studio 2017、.NET 4.6.1 和 EF 6.2 创建了一个 Web 窗体应用程序。每当我在本地运行应用程序时,它都可以正常工作,但是当我发布应用程序并上传到我们的 IIS 服务器时,我会收到屏幕截图中显示的错误。

Error Screenshot

Server Error in '/' Application.
Method not found: 'System.Threading.Tasks.Task`1<!!0> System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync(System.Linq.IQueryable`1<!!0>, System.Linq.Expressions.Expression`1<System.Func`2<!!0,Boolean>>)'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.MissingMethodException: Method not found: 'System.Threading.Tasks.Task`1<!!0> System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync(System.Linq.IQueryable`1<!!0>, System.Linq.Expressions.Expression`1<System.Func`2<!!0,Boolean>>)'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[MissingMethodException: Method not found: 'System.Threading.Tasks.Task`1<!!0> System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync(System.Linq.IQueryable`1<!!0>, System.Linq.Expressions.Expression`1<System.Func`2<!!0,Boolean>>)'.]
   Microsoft.AspNet.Identity.EntityFramework.<GetUserAggregateAsync>d__6c.MoveNext() +0
   System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start(TStateMachine& stateMachine) +174
   Microsoft.AspNet.Identity.EntityFramework.UserStore`6.GetUserAggregateAsync(Expression`1 filter) +199
   Microsoft.AspNet.Identity.Owin.<PasswordSignInAsync>d__29.MoveNext() +150
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13847892
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61
   Microsoft.AspNet.Identity.AsyncHelper.RunSync(Func`1 func) +212
   SupplierPortal.Account.Login.LogIn(Object sender, EventArgs e) in C:\Users\Kobi\Dropbox\Development\WebForms\SupplierPortal_git\SupplierPortal\Account\Login.aspx.cs:39
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +138
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +150
   System.Web.UI.<ProcessRequestMainAsync>d__523.MoveNext() +7834

到目前为止我已经尝试过:

  • 将 EF 降级到早期版本。
  • 检查任何缺少的 using 语句。
  • 从我的参考资料中删除和添加关联的 .dll 文件。
  • 重新编码应用程序以针对早期版本的 .NET
  • 在 web.config 中手动添加指向 .dll 文件的链接
  • 将所有引用的 .dll 设置为复制本地
  • 已确保应用程序池设置为 V4.0
  • 已确保 IIS 已安装最新的 .NET

我注意到堆栈跟踪中的这一行:

SupplierPortal.Account.Login.LogIn(Object sender, EventArgs e) in C:\Users\Kobi\Dropbox\Development\WebForms\SupplierPortal_git\SupplierPortal\Account\Login.aspx.cs:39

引用 Web 服务器上不存在的文件路径,而不是我的本地系统,但是我在 VS 中找不到任何属性来更改或设置它。

在 IIS 服务器上运行的另一个 Web 表单应用程序针对早期版本的 .NET 和 EF。此应用程序运行良好,但据我了解,似乎在我的应用程序中导致问题的异步方法是在更高版本的 EF 中引入的。

非常感谢任何有关此问题的帮助,我在过去几天一直在绞尽脑汁!

【问题讨论】:

  • 您需要在问题中包含相关代码。堆栈跟踪告诉你错误是哪一行。
  • @mason 导致错误的代码是默认的 .NET/EF 授权/身份验证代码,我正在使用 Web 表单身份验证来对我的应用程序的用户进行身份验证。我认为问题不在于代码本身,而在于配置/发布。该应用程序在我的本地计算机上按预期编译和运行,它仅在 IIS 上发布和运行时抛出异常。
  • @mason 应用程序在服务器上运行,但只要调用任何标准 .NET/EF 登录代码,应用程序就会崩溃。
  • 我认为问题不在 EF 中,请检查您的 应用程序池 .Net CLR 版本并确保它针对 V4.0
  • @Ahmed Ragheb 应用程序池当前针对 V4.0 并且服务器已安装 .NET 4.6.1

标签: c# asp.net .net entity-framework webforms


【解决方案1】:

为此我费尽心思,最终创建了一个新的 EC2 实例。该应用程序在上传后运行没有问题。我假设旧实例存在一些配置问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-23
    • 1970-01-01
    • 2011-10-01
    • 1970-01-01
    相关资源
    最近更新 更多