none
Sequence contains no elements error

    Question

  • Does anyone have a clear solution for the "Sequence contains no elements error"?  I have seen posts about this and an entry on the connect site but have seen no solutions.  Is there a hot fix out there for this?  Has this been fixed in the latest VS2012 version?

    Thanks for any information

    Monday, August 13, 2012 9:04 PM

All replies

  • I don't know if this will fix it for you, but one reason this happens is if you have tracing enabled.  I can't remember where, but I read that this could cause the problem, so I turned tracing off and the problem stopped.

    I was seeing the problem when doing the following:

    Check a couple of check boxes, then go back and uncheck one.  When you try to save, you will get the error.  It apparently happens when you "undo" a change with tracing enabled.

    Mark


    • Edited by marks100 Monday, August 13, 2012 10:03 PM
    Monday, August 13, 2012 10:02 PM
  • @marks100 - I doubt that this is the reason. There'd have to be a serious bug in the tracing functionality for this to be the case.

    @CS Dev - you need to provide more information about the code where you're experiencing this problem.


    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer"
     
    By doing this you'll help people find answers faster.

    Tuesday, August 14, 2012 3:50 AM
  • Yann:  

    This is a link to the thread where Eric Erhardt explains that this is a bug in LightSwitch.  You even responded to the thread.

    http://social.msdn.microsoft.com/Forums/en-US/lightswitch/thread/585b4cda-3281-476b-b01b-8e5f69d09882/

    I had this problem and turning off tracing did fix it.

    Mark

    Tuesday, August 14, 2012 12:07 PM
  • Thanks for the feedback.  Yes I did find a mention that tracing could be the cause but I have turned tracing off and the issue still exists.

    As far as the code, I am able to reproduce this on any screen provided I change a value and then set that value back to it's original state.  I could create a new screen with no custom code added and it will reproduce the issue.  I am using an RIA service to connect to my data.  I assumed this bug was reproducible for everyone but, if not, please let me know so I can look deeper into the difference between my implementation and one that does not encounter this issue.

    Tuesday, August 14, 2012 12:39 PM
  • I think I got this same error when trying to populate an ACB with no entries.
    Tuesday, August 14, 2012 3:25 PM
  • After more investigation I have found that when I turn tracing off locally the issue is resolved.  When I turn tracing off in the same application published to Azure, the issue still exists.

    Could this also be related to some type of security that Azure is enforcing that does not exist locally?

    Tuesday, August 14, 2012 3:32 PM
  • This is a link to the thread where Eric Erhardt explains that this is a bug in LightSwitch.  You even responded to the thread.

    http://social.msdn.microsoft.com/Forums/en-US/lightswitch/thread/585b4cda-3281-476b-b01b-8e5f69d09882/

    Except that the OP had not provided any information beyond the exception message. "Sequence contains no elements" is a InvalidOperationException that comes from using LINQ over an enumerable that has a size of zero. You can even produce the same exception and message outside the context of a LightSwitch application, for example, a console application:

    int value = Enumerable.Empty<int>().Single();

    Assuming that it the same exact problem with such little information is a little hasty. So at the time of his posting, Yann's doubt and request for more info was appropriate.

    However, the OP has tried your suggestion (since Yann's post), which has helped rid of the exception in one scenario, but seems to still persist. We'll only be able to help in a more directed manner if call stack information or reproduction steps are provided.


    Justin Anderson, LightSwitch Development Team

    Wednesday, August 15, 2012 4:30 AM
  • Could you provide call stack information when the exception occurs or tell us how to reproduce the issue? We can guess at what the problem is, but we don't have much information to use yet.

    Justin Anderson, LightSwitch Development Team

    Wednesday, August 15, 2012 4:31 AM
  • @Justin - thanks!

    @marks100 - it would seem that I ended up being wrong, so thanks for adding the link to Eric's post.


    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer"
     
    By doing this you'll help people find answers faster.

    Thursday, August 16, 2012 3:33 AM
  • sorry for the slow turnaround on the response and I appreciate the replies.  Below is the stack trace from the Save with trace turned on (this was the only way I could capture the stack in Azure):

    Microsoft.LightSwitch.DataService [Microsoft.LightSwitch.DataService][Application:Error][LightSwitchApplication.DomainServiceData:SaveChanges]
    An exception has occurred:  Microsoft.LightSwitch.DataServiceOperationException:
    Sequence contains no elements ---> System.InvalidOperationException: Sequence
    contains no elements
      at
    System.Linq.Enumerable.Aggregate[TSource](IEnumerable`1 source, Func`3
    func)
      at
    Microsoft.LightSwitch.ServerGenerated.Platform.Internal.DataServiceLoggingHelper.LogChangeSetContents(String
    messageHeader)
      at
    Microsoft.LightSwitch.ServerGenerated.Implementation.DataServiceImplementation`1.Microsoft.LightSwitch.ServerGenerated.Implementation.IServerDataServiceImplementationCore.Submit()
      at
    Microsoft.LightSwitch.ServerGenerated.Implementation.DomainService`1.InvokeSubmit()
      at
    Microsoft.LightSwitch.ServerGenerated.Implementation.DomainService`1.<PersistChangeSet>b__17()
      at
    Microsoft.LightSwitch.ServerGenerated.Implementation.DataServiceImplementation`1.Microsoft.LightSwitch.ServerGenerated.Implementation.IServerDataServiceImplementationCore.InvokeOperation[T](String
    operationName, Object[] args, Boolean invokedFromClient, Func`1 invokeOperation,
    Action catchCallback)
      --- End of inner exception stack trace ---
    Thursday, August 16, 2012 1:53 PM