Sequence contains no elements server side - c#

I am developing a Asp.net MVC web application and have been deploying to a web server for a few months now. Just recently I have experienced a new error that confused me. Upon publishing my application, and loading up the website, I get the following error message:
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
I am very confused, because the application runs perfectly on localhost, without any issue or error message. I also checked my database, and it is also connected and validated to the server. So there should be no error.
Thanks for any help in advance!

Check in your code to make sure FirstOrDefault() or SingleOrDefault() is used instead of using any of these: First() or 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?

Related

Intermittent "The operation timed out" error on production server

I have a web API(service) whose target framework is .net core 2.0.
This service is calling a custom identity server 4 endpoint using HttpClient by using the 'using' statement. This call always works fine on the development/UAT server.
But on all production servers, it fails intermittently and throws the following exception:
One or more errors occurred. (An error occurred while sending the
request.) Exception: System.AggregateException: One or more errors
occurred. (An error occurred while sending the request.) --->
System.Net.Http.HttpRequestException: An error occurred while sending
the request. ---> System.Net.Http.WinHttpException: The operation
timed out at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
System.Threading.Tasks.RendezvousAwaitable`1.GetResult() at
System.Net.Http.WinHttpHandler.d__105.MoveNext() ---
End of inner exception stack trace --- at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at
System.Net.Http.HttpClient.d__58.MoveNext()
--- End of inner exception stack trace --- at System.Threading.Tasks.Task`1.GetResultCore(Boolean
waitCompletionNotification) at Get(String a, String b)
I went through related stack-overflow posts, some suggested making HttpClient static as it might throw socket exhaustion error. But I am not getting that error either I am able to reproduce this issue on a development server. I created a console application and called this service 64k times, but still, it worked properly.
How to stop outbound HTTP connections from timing out
Asp.net Core HttpClient has many TIME_WAIT or CLOSE_WAIT connections
Can someone please tell me, what can be the reason for this intermittent error only on the production server or is there any way I can reproduce this issue on the dev server. I have tried by making many calls to service, but still unable to reproduce the error.

Unhandled exception in ASP web.config connectionString setting

I am running an ASP website and connect to a SQL database, very standard setup. The connection string details are held in the <connectionStrings> tag of the web.config file.
If the database username/password details are not correct, I get an YSOD unhandled exception notice. This is not at all surprising, but I would like to show a custom error page instead. However, I cannot seem to get the custom page to show using <customErrors> settings.
It seems an unhandled exception at the web.config level (for example the incorrect database connection string) means the application does not get as far as redirecting to the custom error page.
Any advice on how to handle this exception would be much appreciated. I understand if the exception happened on a particular page I can add a try/catch to catch it. I am not sure where/how I can handle this exception:
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.Data.SqlClient.SqlException: Login failed for user xxxxx
Find place where this connection string is used and handle exception there.

Am getting this exception, System.Data.SqlClient.SqlException

String or binary data would be truncated.
The statement has been terminated.
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.Data.SqlClient.SqlException: String or binary data would be truncated.
I am getting this exception even after I did undo changes for the page, please someone help me to come out of this. *
You are trying to insert a data (string or binary) longer than the maximum length possible for the target field.
I agree with Morix Dev, your columndefintion is too small.
The exception dosnt report which column is too small. But you could log out the data before insert, and check them against the definition.

FluentNHibernate - Could not configure datastore from input stream (XmlDocument)

I have a legacy WCF service using FluentNHibernate (along side EF and stored procs). The service was working fine for over an year. Recently we change the apppool recycle settings from default to make apppool recycle at 10 AM every day. Since that change, at least twice, my WCF service has failed with following exception
FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
---> FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
---> NHibernate.MappingException: Could not configure datastore from input stream (XmlDocument) ---> System.NullReferenceException: Object reference not set to an instance of an object.
at NHibernate.Cfg.MappingsQueue.GetNextAvailableResource()
at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name)
--- End of inner exception stack trace ---
at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)
at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name)
at NHibernate.Cfg.Configuration.AddDocument(XmlDocument doc, String name)
at FluentNHibernate.PersistenceModel.Configure(Configuration cfg)
at FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg)
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
--- End of inner exception stack trace ---
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
--- End of inner exception stack trace ---
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
A few interesting things to note
Both times, the error has started appearing few seconds after the apppool recycle which makes me believe this is closely related to that
This does not happen after every apppool recycle
This does not happen in our test environments where apppool recycle setting is IIS default
This is very difficult to reproduce locally. I have looked at following SO questions regarding the same exceptions but they are in a completely different context and the authors of those questions are getting that exception consistently which is not the case here
Runtime error when trying to run Fluent NHibernate tutorial example
Fluent nHibernate error - Could not compile the mapping document: (XmlDocument)
After hours of investigation, it came down to be an issue of multiple threads trying to create session factory. I would have thought that NH session factory is thread-safe but sadly it isn't and I had to put int code to make it thread-safe.

`Server Error in '/' Application. No such host is known

I am getting this error on one website which is deployed in IIS , when i browse from network system i am getting this error .
other websites are working fine
`Server Error in '/' Application.
No such host is known
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.Net.Sockets.SocketException: No such host is known
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:
[SocketException (0x2af9): No such host is known]
System.Net.Dns.InternalGetHostByAddress(IPAddress address, Boolean includeIPv6) +3192148
System.Net.Dns.GetHostEntry(String hostNameOrAddress) +8777246
_Default.Page_Load(Object sender, EventArgs e) +320
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3178`enter code here`
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18055'`
What you have here is one unhanded exception when you call the Dns.GetHostEntry as seen on the stack trace, and on the clear message that you have.
Wrap this part of the code with try/catch and log the error on your system. If its critical for you to know the dns name, then you need to show an error page with further instructions.

Categories