Skip to content

Using First() instead of FirstOrDefault() causes exception with empty list #1

@Komarulon

Description

@Komarulon

I'm not sure exactly what the cause is but it's happening in Component.cs, line 164. It's happening at least for me when starting a run.

Linq First() throws a System.InvalidOperationException when you start the run if no matching categories are found, where FirstOrDefault() will return null.

************** Exception Text **************
System.InvalidOperationException: Sequence contains no elements
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
at LiveSplit.UI.Components.USB2SNESComponent._state_OnStart(Object sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at LiveSplit.Model.TimerModel.Start()
at LiveSplit.UI.Components.USB2SNESComponent.UpdateSplits()
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions