dotnet / upgrade-assistant

A tool to assist developers in upgrading .NET Framework applications to .NET 6 and beyond
MIT License
1.11k stars 163 forks source link

UWP to WinUI3 upgrade: System.InvalidOperationException: Sequence contains no elements #1153

Closed myokeeh closed 2 years ago

myokeeh commented 2 years ago

Describe the bug

I'm trying out the UWP to WinUI3 upgrade, but it fails at the following step. The two solutions I've tried are ones made via Windows Template Studio (pre 5.0)

Apply next step (Apply fix for [UA306_A1, UA306_A2, UA306_A3, UA306_A4, UA306_B, UA306_C, UA306_D, UA306_E, UA306_F, UA306_G, UA306_H, UA306_I]: Replace usage of Windows.UI.Core.CoreDispatcher, Replace usage of Window.Current.Dispatcher, Replace usage of App.Window.Dispatcher, Replace usage of Window.Dispatcher, Replace usage of Windows.Media.Capture.CameraCaptureUI, Replace usage of Micorsoft.UI.Xaml.Controls.InkCanvas, Replace usage of Microsoft.UI.Xaml.Controls.Maps.MapControl, Replace usage of Microsoft.UI.Xaml.Controls.MediaElement, Replace usage of Windows.Graphics.Printing.PrintManager, Replace usage of Windows.Security.Authentication.Web.WebAuthenticationBroker, Replace usage of Windows.UI.Xaml.Media.AcrylicBrush.BackgroundSource, Replace usage of Windows.UI.Shell.TaskbarManager)

Exceptions (if any)

Unexpected error applying step
System.InvalidOperationException: Sequence contains no elements
   at System.Linq.ThrowHelper.ThrowNoElementsException()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at Microsoft.DotNet.UpgradeAssistant.Extensions.Windows.WinUIApiAlertCodeFixer.RegisterCodeFixesAsync(CodeFixContext context)
   at Microsoft.DotNet.UpgradeAssistant.Steps.Source.CodeFixerStep.TryFixDiagnosticAsync(Diagnostic diagnostic, Document document, CancellationToken token)
   at Microsoft.DotNet.UpgradeAssistant.Steps.Source.CodeFixerStep.ApplyImplAsync(IUpgradeContext context, CancellationToken token)
   at Microsoft.DotNet.UpgradeAssistant.UpgradeStep.ApplyAsync(IUpgradeContext context, CancellationToken token) in /_/src/common/Microsoft.DotNet.UpgradeAssistant.Abstractions/UpgradeStep.cs:line 178

Further technical details

3.1.419 [C:\Program Files\dotnet\sdk] 5.0.101 [C:\Program Files\dotnet\sdk] 5.0.103 [C:\Program Files\dotnet\sdk] 5.0.201 [C:\Program Files\dotnet\sdk] 5.0.214 [C:\Program Files\dotnet\sdk] 5.0.302 [C:\Program Files\dotnet\sdk] 6.0.105 [C:\Program Files\dotnet\sdk] 6.0.202 [C:\Program Files\dotnet\sdk] 6.0.203 [C:\Program Files\dotnet\sdk] 6.0.300 [C:\Program Files\dotnet\sdk]

0.3.330701+fa00bab2d06aab9c710c344c0f32440ad4eb8410

sunandabalu commented 2 years ago

@ujjwalchadha Could you take a look?

ujjwalchadha commented 2 years ago

Fixed by #1157 If this still persists, will reopen and take another look.

myokeeh commented 2 years ago

@ujjwalchadha, I just tried 0.3.331501 and it seems the Exception is now gone, but it still fails at this step:

[01:32:58 WRN] No code fix found for UA306_A1
[01:32:58 ERR] Failed to fix diagnostic UA306_A1 in C:\APP\Services\ViewLifetimeControl.cs
[01:32:58 WRN] Upgrade step Apply fix for [UA306_A1, UA306_A2, UA306_A3, UA306_A4, UA306_B, UA306_C, UA306_D, UA306_E, UA306_F, UA306_G, UA306_H, UA306_I]: Replace usage of Windows.UI.Core.CoreDispatcher, Replace usage of Window.Current.Dispatcher, Replace usage of App.Window.Dispatcher, Replace usage of Window.Dispatcher, Replace usage of Windows.Media.Capture.CameraCaptureUI, Replace usage of Micorsoft.UI.Xaml.Controls.InkCanvas, Replace usage of Microsoft.UI.Xaml.Controls.Maps.MapControl, Replace usage of Microsoft.UI.Xaml.Controls.MediaElement, Replace usage of Windows.Graphics.Printing.PrintManager, Replace usage of Windows.Security.Authentication.Web.WebAuthenticationBroker, Replace usage of Windows.UI.Xaml.Media.AcrylicBrush.BackgroundSource, Replace usage of Windows.UI.Shell.TaskbarManager failed: Failed: Failed to fix diagnostic UA306_A1 in C:\APP\Services\ViewLifetimeControl.cs
Command (Apply next step (Apply fix for [UA306_A1, UA306_A2, UA306_A3, UA306_A4, UA306_B, UA306_C, UA306_D, UA306_E, UA306_F, UA306_G, UA306_H, UA306_I]: Replace usage of Windows.UI.Core.CoreDispatcher, Replace usage of Window.Current.Dispatcher, Replace usage of App.Window.Dispatcher, Replace usage of Window.Dispatcher, Replace usage of Windows.Media.Capture.CameraCaptureUI, Replace usage of Micorsoft.UI.Xaml.Controls.InkCanvas, Replace usage of Microsoft.UI.Xaml.Controls.Maps.MapControl, Replace usage of Microsoft.UI.Xaml.Controls.MediaElement, Replace usage of Windows.Graphics.Printing.PrintManager, Replace usage of Windows.Security.Authentication.Web.WebAuthenticationBroker, Replace usage of Windows.UI.Xaml.Media.AcrylicBrush.BackgroundSource, Replace usage of Windows.UI.Shell.TaskbarManager)) did not succeed
ujjwalchadha commented 2 years ago

Can you send the .clef file that is generated in the project?

myokeeh commented 2 years ago

@ujjwalchadha upgrade-assistant.clef.txt

ujjwalchadha commented 2 years ago

@myokeeh is it possible to send the repro code (The dispatcher queue related code in ViewLifetimeControl.cs) from the project that failed?

myokeeh commented 2 years ago

@ujjwalchadha this is the code that is generated by the tool as a result of the upgrade ViewLifetimeControl.cs.txt .

ujjwalchadha commented 2 years ago

Thanks! Tracking the new issue here: #1171 Closing this one as it seems to be a separate issue.

ujjwalchadha commented 2 years ago

1172 should fix the new issue