dotnet / upgrade-assistant

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

ArgumentNullException in "UA0001: ASP.NET Core projects should not reference ASP.NET namespaces" #893

Open dotjpg3141 opened 2 years ago

dotjpg3141 commented 2 years ago

Describe the bug

I'm getting a ArgumentNullException in the step Apply code fixes to Razor documents for UA0001:

To Reproduce

upgrade-assistant --ignore-unsupported-features --non-interactive --skip-backup xy.sln

Exceptions (if any)

[11:30:39 INF] Loaded 6 extensions
[11:30:40 INF] Using MSBuild from C:\Program Files\dotnet\sdk\5.0.401\
[11:30:40 INF] Using Visual Studio install from C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise [v16]
[11:30:43 INF] Loading upgrade progress file at D:\src\XY\.upgrade-assistant
[11:30:43 INF] Initializing upgrade step Back up project
[11:30:43 INF] Initializing upgrade step Convert project file to SDK style
[11:30:45 INF] Initializing upgrade step Clean up NuGet package references
[11:33:17 INF] No package updates needed
[11:33:17 INF] Initializing upgrade step Update TFM
[11:33:20 INF] Recommending executable TFM net5.0 because the project builds to an executable
[11:33:20 INF] TFM needs updated to net5.0

...

[11:39:33 INF] Identified 34 diagnostics in project XY

[11:39:35 INF] Applying upgrade step Apply fix for UA0001: ASP.NET Core projects should not reference ASP.NET namespaces
[11:39:35 ERR] Unexpected error applying step
System.ArgumentNullException: Value cannot be null. (Parameter 'document')
   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
Command (Apply next step (Apply fix for UA0001: ASP.NET Core projects should not reference ASP.NET namespaces)) did not succeed

Further technical details

Edit1: The analyzer step is pretty slow 15-30 seconds per Applying upgrade step * 34 diagnostics. Edit2: The upgrade assistant might be in an infinite loop. I'm currently at 100+ attempted code fixes. Edit3: Is there a way to skip certain steps when using --non-interactive?

sunandabalu commented 2 years ago

@dotjpg3141 Thanks for filing this issue. We are aware of perf issues that we are looking at , I have added the one you mentioned to the list - https://github.com/dotnet/upgrade-assistant/issues/895 - as well. We currently do not have support for skipping steps in --non-interactive unfortunately, as part of enabling solution wide update we are looking at making changes to step so users can specify what steps they want to execute - https://github.com/dotnet/upgrade-assistant/issues/381.

Adding @mjrousos to take a look at the failure here.

sunandabalu commented 2 years ago

@dotjpg3141 Could you provide the cshtml file you were trying to upgrade?

georgikoemdzhiev commented 2 years ago

I am encountering the same issue. Is there a way to tell which Razor document is causing this?