gpt4 book ai didi

c# - 序列不包含任何元素服务器端

转载 作者:搜寻专家 更新时间:2023-10-30 20:54:02 24 4
gpt4 key购买 nike

我正在开发一个 Asp.net MVC 网络应用程序,并且已经部署到网络服务器几个月了。就在最近,我遇到了一个让我困惑的新错误。在发布我的应用程序并加载网站后,我收到以下错误消息:

 Sequence contains no elements

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.InvalidOperationException: Sequence contains no elements

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:


[InvalidOperationException: Sequence contains no elements]
System.Linq.Enumerable.First(IEnumerable`1 source) +514
System.Linq.Queryable.First(IQueryable`1 source) +330
LabSys.MvcApplication.Application_AuthorizeRequest(Object sender, EventArgs e) +1261
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +92
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&completedSynchronously) +165

我很困惑,因为应用程序在本地主机上运行完美,没有任何问题或错误消息。我还检查了我的数据库,它也已连接并验证到服务器。所以应该不会出错。

提前感谢您的帮助!

最佳答案

检查您的代码以确保使用 FirstOrDefault()SingleOrDefault() 而不是使用以下任何一个:First()Single()

When you get theLINQ Error "Sequence contains no elements", this is usually because you are using the First() or Single() command rather than FirstOrDefault() and SingleOrDefault().

Sequence contains no elements?

关于c# - 序列不包含任何元素服务器端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30945692/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com