Skip to content

Analyzers that make changes to AdditionalFiles are not having their changes persisted #952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JoeRobich opened this issue Feb 4, 2021 · 10 comments · Fixed by #1106
Closed
Labels
Feature Request This issue is requesting an enhancement or new feature
Milestone

Comments

@JoeRobich
Copy link
Member

Analyzers such as the PublicApiAnalyzer will write updates to non-code files. We should support reporting and persisting these changes.

See dotnet/roslyn#48561 (comment)

@Pilchie
Copy link
Member

Pilchie commented Feb 4, 2021

The ASP.NET team would very much like to see this, as we've adopted PublicAPI Analyzer, but if you're not in VS, it can be quite difficult to update the public API files, or when large changes are made (AspNetCore.sln is around 500 projects, so fix all can be a bit of a pain).

@Pilchie
Copy link
Member

Pilchie commented Apr 26, 2021

Oh, nice! @dougbu we should try picking up the next release of dotnet format that has this, and see if we can use it for updating public api analyzer files on the command line/on linux, etc.

@dougbu
Copy link

dougbu commented Apr 26, 2021

Yup❕❕ The other fix I wanted to pick up was for #1192.

@JoeRobich dotnet-roslyn-analyzers CI hasn't built since Thursday (for 'main') or Friday (for 'release/6.0.1xx'). Is that the right pipeline to watch❔ And, which branch should we be using❔ The current Microsoft.CodeAnalysis.PublicApiAnalyzers version in dotnet/aspnetcore is 3.3.0 if that matters.

Ideal would be to get various fixes in our 'release/5.0' branch too. But, I seem to remember relying on non-stabilized versions in servicing branches causes problems. Does that mean we have to wait for a real 3.3.3 release to pick up the latest in 'release/5.0'❔

@dougbu
Copy link

dougbu commented Apr 26, 2021

Oops I got muddled this repo with roslyn-analyzers.

@JoeRobich what's the correct way to invoke dotnet format to fix the Microsoft.CodeAnalysis.PublicApiAnalyzers files❔ What's the minimum dotnet format version we'll need for this fix❔ And, will we also need a new version of Microsoft.CodeAnalysis.PublicApiAnalyzers❔

@Pilchie we don't automate dotnet format in dotnet/aspnetcore at all. Any reason to do more than document using dotnet format to correct issues that show up in CI builds❔

@JoeRobich
Copy link
Member Author

@dougbu You can use our latest 5.1 build (5.1.222801) using the following command:

dotnet tool install -g dotnet-format --version 5.1.* --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json

If you would like to specifically fix these PublicAPI issues, you can run the following command (Assumes the analyzers are added as package references to your projects):

dotnet format AspNetCore.sln --fix-analyzers warn --diagnostics RS0016

Otherwise, you can run a more general command like the following to fix up whitespace, codestyle, and analyzer issues.

dotnet format AspNetCore.sln -w -s warn -a warn 

@dougbu
Copy link

dougbu commented Apr 30, 2021

Unfortunately, dotnet format fails quite reliably when run against AspNetCore.sln. Two main problems:

  1. The documentation for --diagnostics seems to be incorrect. Even though I see tests of commands using options like --diagnostics RS0016, such commands don't work e.g.
> dotnet format .\AspNetCore.sln --fix-analyzers warn --no-restore --diagnostics RS0016
Unrecognized command or argument 'RS0016'

dotnet-format:
  dotnet-format
...
  1. While commands like the following are accepted, they crash the tool.
dotnet format .\AspNetCore.sln --fix-analyzers warn --no-restore --diagnostics=RS0016

or

dotnet format .\AspNetCore.sln --fix-analyzers warn --no-restore

or, to suppress a common Warnings were encountered while loading the workspace. Set the verbosity option to the 'diagnostic' level to log warnings. message,

dotnet format .\AspNetCore.sln --fix-analyzers warn --no-restore --diagnostics=RS0016 --verbosity diag

Details of the crash

> dotnet format .\AspNetCore.sln --fix-analyzers warn --no-restore --diagnostics=RS0016 --verbosity diag
  The dotnet format version is '6.0.222803+8846611561f5491139f9f15365ea947a9bce9b2d'.
  The dotnet runtime version is '6.0.0-preview.5.21227.7'.
  The dotnet CLI version is '6.0.100-preview.4.21222.6'.
  Using MSBuild.exe located in 'C:\dd\dnx\w\aspnetcore\.dotnet\sdk\6.0.100-preview.4.21222.6\'.
  Formatting code files in workspace 'C:\dd\dnx\w\aspnetcore\AspNetCore.sln'.
  Loading workspace.
Found project reference without a matching metadata reference: C:\dd\dnx\w\aspnetcore\src\Http\Metadata\src\Microsoft.AspNetCore.Metadata.csproj
Found project reference without a matching metadata reference: C:\dd\dnx\w\aspnetcore\src\Localization\Abstractions\src\Microsoft.Extensions.Localization.Abstractions.csproj
Found project reference without a matching metadata reference: C:\dd\dnx\w\aspnetcore\src\DataProtection\Cryptography.Internal\src\Microsoft.AspNetCore.Cryptography.Internal.csproj
Found project reference without a matching metadata reference: C:\dd\dnx\w\aspnetcore\src\DataProtection\Abstractions\src\Microsoft.AspNetCore.DataProtection.Abstractions.csproj
Found project reference without a matching metadata reference: C:\dd\dnx\w\aspnetcore\src\DataProtection\DataProtection\src\Microsoft.AspNetCore.DataProtection.csproj
Found project reference without a matching metadata reference: C:\dd\dnx\w\aspnetcore\src\Servers\Connections.Abstractions\src\Microsoft.AspNetCore.Connections.Abstractions.csproj
Found project reference without a matching metadata reference: C:\dd\dnx\w\aspnetcore\src\Analyzers\Microsoft.AspNetCore.Analyzer.Testing\src\Microsoft.AspNetCore.Analyzer.Testing.csproj
Found project reference without a matching metadata reference: C:\dd\dnx\w\aspnetcore\src\Components\WebAssembly\testassets\Wasm.Authentication.Shared\Wasm.Authentication.Shared.csproj
Found project reference without a matching metadata reference: C:\dd\dnx\w\aspnetcore\src\DataProtection\Cryptography.KeyDerivation\src\Microsoft.AspNetCore.Cryptography.KeyDerivation.csproj
Found project reference without a matching metadata reference: C:\dd\dnx\w\aspnetcore\src\Identity\Extensions.Core\src\Microsoft.Extensions.Identity.Core.csproj
Found project reference without a matching metadata reference: C:\dd\dnx\w\aspnetcore\src\Identity\Extensions.Stores\src\Microsoft.Extensions.Identity.Stores.csproj
Found project reference without a matching metadata reference: C:\dd\dnx\w\aspnetcore\src\HealthChecks\Abstractions\src\Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions.csproj
Found project reference without a matching metadata reference: C:\dd\dnx\w\aspnetcore\src\Middleware\Localization\testassets\ResourcesClassLibraryNoAttribute\ResourcesClassLibraryNoAttribute.csproj
Found project reference without a matching metadata reference: C:\dd\dnx\w\aspnetcore\src\Middleware\Localization\testassets\ResourcesClassLibraryWithAttribute\ResourcesClassLibraryWithAttribute.csproj
Found project reference without a matching metadata reference: C:\dd\dnx\w\aspnetcore\src\Razor\Microsoft.AspNetCore.Razor.Language\src\Microsoft.AspNetCore.Razor.Language.csproj
Found project reference without a matching metadata reference: C:\dd\dnx\w\aspnetcore\src\Razor\Microsoft.CodeAnalysis.Razor\src\Microsoft.CodeAnalysis.Razor.csproj
Found project reference without a matching metadata reference: C:\dd\dnx\w\aspnetcore\src\Razor\Microsoft.AspNetCore.Mvc.Razor.Extensions\src\Microsoft.AspNetCore.Mvc.Razor.Extensions.csproj
Found project reference without a matching metadata reference: C:\dd\dnx\w\aspnetcore\src\Mvc\Mvc.Api.Analyzers\src\Microsoft.AspNetCore.Mvc.Api.Analyzers.csproj
Found project reference without a matching metadata reference: C:\dd\dnx\w\aspnetcore\src\Razor\test\Microsoft.AspNetCore.Razor.Test.ComponentShim\Microsoft.AspNetCore.Razor.Test.ComponentShim.csproj
Found project reference without a matching metadata reference: C:\dd\dnx\w\aspnetcore\src\Razor\test\Microsoft.AspNetCore.Razor.Test.Common\Microsoft.AspNetCore.Razor.Test.Common.csproj
Found project reference without a matching metadata reference: C:\dd\dnx\w\aspnetcore\src\Shared\test\testassets\ThrowingLibrary\ThrowingLibrary.csproj
Cannot open project 'C:\dd\dnx\w\aspnetcore\src\Servers\IIS\AspNetCoreModuleV2\AspNetCore\AspNetCore.vcxproj' because the file extension '.vcxproj' is not associated with a language.
Cannot open project 'C:\dd\dnx\w\aspnetcore\src\Servers\IIS\AspNetCoreModuleV2\CommonLib\CommonLib.vcxproj' because the file extension '.vcxproj' is not associated with a language.
Cannot open project 'C:\dd\dnx\w\aspnetcore\src\Servers\IIS\AspNetCoreModuleV2\CommonLibTests\CommonLibTests.vcxproj' because the file extension '.vcxproj' is not associated with a language.
Cannot open project 'C:\dd\dnx\w\aspnetcore\src\Servers\IIS\AspNetCoreModuleV2\gtest\gtest.vcxproj' because the file extension '.vcxproj' is not associated with a language.
Cannot open project 'C:\dd\dnx\w\aspnetcore\src\Servers\IIS\AspNetCoreModuleV2\IISLib\IISLib.vcxproj' because the file extension '.vcxproj' is not associated with a language.
Cannot open project 'C:\dd\dnx\w\aspnetcore\src\Servers\IIS\AspNetCoreModuleV2\InProcessRequestHandler\InProcessRequestHandler.vcxproj' because the file extension '.vcxproj' is not associated with a language.
Cannot open project 'C:\dd\dnx\w\aspnetcore\src\Servers\IIS\AspNetCoreModuleV2\OutOfProcessRequestHandler\OutOfProcessRequestHandler.vcxproj' because the file extension '.vcxproj' is not associated with a language.
Cannot open project 'C:\dd\dnx\w\aspnetcore\src\Servers\IIS\AspNetCoreModuleV2\RequestHandlerLib\RequestHandlerLib.vcxproj' because the file extension '.vcxproj' is not associated with a language.
Found project reference without a matching metadata reference: C:\dd\dnx\w\aspnetcore\src\SiteExtensions\Microsoft.Web.Xdt.Extensions\src\Microsoft.Web.Xdt.Extensions.csproj
Cannot open project 'C:\dd\dnx\w\aspnetcore\src\Http\samples\MinimalSampleFSharp\MinimalSampleFSharp.fsproj' because the file extension '.fsproj' is not associated with a language.
  Project BaselineGenerator is using configuration from 'C:\dd\dnx\w\aspnetcore\.editorconfig'.
  Project BaselineGenerator is using configuration from 'C:\dd\dnx\w\aspnetcore\.globalconfig'.
  Project BaselineGenerator is using configuration from 'C:\dd\dnx\w\aspnetcore\artifacts\obj\BaselineGenerator\Debug\net6.0\BaselineGenerator.GeneratedMSBuildEditorConfig.editorconfig'.
  Project BaselineGenerator is using configuration from 'C:\dd\dnx\w\aspnetcore\.dotnet\sdk\6.0.100-preview.4.21222.6\Sdks\Microsoft.NET.Sdk\analyzers\build\config\AnalysisLevel_5_Default.editorconfig'.
  Project RepoTasks(net6.0) is using configuration from 'C:\dd\dnx\w\aspnetcore\.editorconfig'.
  Project RepoTasks(net6.0) is using configuration from 'C:\dd\dnx\w\aspnetcore\.globalconfig'.
...
  Project ServerComparison.TestSites is using configuration from 'C:\dd\dnx\w\aspnetcore\artifacts\obj\ServerComparison.TestSites\Debug\net6.0\ServerComparison.TestSites.GeneratedMSBuildEditorConfig.editorconfig'.
  Project ServerComparison.TestSites is using configuration from 'C:\dd\dnx\w\aspnetcore\.dotnet\sdk\6.0.100-preview.4.21222.6\Sdks\Microsoft.NET.Sdk\analyzers\build\config\AnalysisLevel_5_Default.editorconfig'.
  Complete in 122523ms.
  Determining formattable files.
  Complete in 36682ms.
  Running formatters.
Unhandled exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.Assembly.GetTypes() in System.Private.CoreLib.dll:token 0x6004bd1+0x0
   at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerFinderHelpers.<>c.<LoadAnalyzersAndFixers>b__0_0(Assembly assembly) in /_/src/Analyzers/AnalyzerFinderHelpers.cs:line 18
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext() in System.Linq.dll:token 0x6000219+0x0
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() in System.Linq.dll:token 0x6000253+0x0
   at System.Linq.Enumerable.OfTypeIterator[TResult](IEnumerable source)+MoveNext() in System.Linq.dll:token 0x600005d+0x8e
   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items) in System.Linq.dll:token 0x6000014+0x6d
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source) in System.Linq.dll:token 0x6000029+0x0
   at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items) in System.Collections.Immutable.dll:token 0x600014c+0x29
   at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerFinderHelpers.LoadAnalyzersAndFixers(IEnumerable`1 assemblies) in /_/src/Analyzers/AnalyzerFinderHelpers.cs:line 23
   at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerReferenceInformationProvider.GetAnalyzersAndFixers(Project project) in /_/src/Analyzers/AnalyzerReferenceInformationProvider.cs:line 31
   at System.Collections.Immutable.ImmutableDictionary.<>c__DisplayClass9_0`3.<ToImmutableDictionary>b__0(TSource element) in System.Collections.Immutable.dll:token 0x6000221+0x0
   at System.Linq.Utilities.<>c__DisplayClass2_0`3.<CombineSelectors>b__0(TSource x) in System.Linq.dll:token 0x6000427+0x0
   at System.Linq.Enumerable.SelectIListIterator`2.MoveNext() in System.Linq.dll:token 0x60001f4+0x36
   at System.Collections.Immutable.ImmutableDictionary`2.AddRange(IEnumerable`1 items, MutationInput origin, KeyCollisionBehavior collisionBehavior) in System.Collections.Immutable.dll:token 0x600026c+0x98
   at System.Collections.Immutable.ImmutableDictionary`2.AddRange(IEnumerable`1 pairs, Boolean avoidToHashMap) in System.Collections.Immutable.dll:token 0x6000271+0x33
   at System.Collections.Immutable.ImmutableDictionary`2.AddRange(IEnumerable`1 pairs) in System.Collections.Immutable.dll:token 0x600023b+0xb
   at System.Collections.Immutable.ImmutableDictionary.ToImmutableDictionary[TSource,TKey,TValue](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 keyComparer, IEqualityComparer`1 valueComparer) in System.Collections.Immutable.dll:token 0x6000214+0x0
   at System.Collections.Immutable.ImmutableDictionary.ToImmutableDictionary[TSource,TKey,TValue](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector) in System.Collections.Immutable.dll:token 0x6000219+0x0
   at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerReferenceInformationProvider.GetAnalyzersAndFixers(Solution solution, FormatOptions formatOptions, ILogger logger) in /_/src/Analyzers/AnalyzerReferenceInformationProvider.cs:line 25
   at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerFormatter.FormatAsync(Solution solution, ImmutableArray`1 formattableDocuments, FormatOptions formatOptions, ILogger logger, List`1 formattedFiles, CancellationToken cancellationToken) in /_/src/Analyzers/AnalyzerFormatter.cs:line 61
   at Microsoft.CodeAnalysis.Tools.CodeFormatter.RunCodeFormattersAsync(Solution solution, ImmutableArray`1 formattableDocuments, FormatOptions formatOptions, ILogger logger, List`1 formattedFiles, CancellationToken cancellationToken) in /_/src/CodeFormatter.cs:line 162
   at Microsoft.CodeAnalysis.Tools.CodeFormatter.FormatWorkspaceAsync(FormatOptions formatOptions, ILogger logger, CancellationToken cancellationToken, String binaryLogPath) in /_/src/CodeFormatter.cs:line 83
   at Microsoft.CodeAnalysis.Tools.Program.Run(String workspace, Boolean noRestore, Boolean folder, Boolean fixWhitespace, String fixStyle, String fixAnalyzers, String[] diagnostics, String verbosity, Boolean check, String[] include, String[] exclude, String report, Boolean includeGenerated, String binarylog, IConsole console) in /_/src/Program.cs:line 185
   at System.CommandLine.Invocation.CommandHandler.GetResultCodeAsync(Object value, InvocationContext context) in System.CommandLine.dll:token 0x600021b+0xb6
   at System.CommandLine.Invocation.ModelBindingCommandHandler.InvokeAsync(InvocationContext context) in System.CommandLine.dll:token 0x600023f+0x108
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext() in System.CommandLine.dll:token 0x6000526+0xa5
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseErrorReporting>b__21_0>d.MoveNext() in System.CommandLine.dll:token 0x6000532+0x90
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseHelp>b__0>d.MoveNext() in System.CommandLine.dll:token 0x600053a+0x85
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass25_0.<<UseVersionOption>b__0>d.MoveNext() in System.CommandLine.dll:token 0x6000540+0xa6
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<<UseTypoCorrections>b__0>d.MoveNext() in System.CommandLine.dll:token 0x600053e+0xc9
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__22_0>d.MoveNext() in System.CommandLine.dll:token 0x6000534+0xcd
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseDirective>b__20_0>d.MoveNext() in System.CommandLine.dll:token 0x6000530+0x94
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseDebugDirective>b__11_0>d.MoveNext() in System.CommandLine.dll:token 0x600052e+0x12f
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext() in System.CommandLine.dll:token 0x600052c+0xf0
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<<UseExceptionHandler>b__0>d.MoveNext() in System.CommandLine.dll:token 0x6000538+0x70
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
   at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly) in System.Private.CoreLib.dll:token 0x6004dd0+0x8
   at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, RuntimeAssembly requestingAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, AssemblyLoadContext assemblyLoadContext) in System.Private.CoreLib.dll:token 0x6004dcf+0x16
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName) in System.Private.CoreLib.dll:token 0x60035d5+0xe
   at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerReferenceInformationProvider.AnalyzerLoadContext.Load(AssemblyName assemblyName) in /_/src/Analyzers/AnalyzerReferenceInformationProvider.cs:line 98
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName) in System.Private.CoreLib.dll:token 0x60035e6+0x20
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName) in System.Private.CoreLib.dll:token 0x60035e3+0x7
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
   at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly) in System.Private.CoreLib.dll:token 0x6004dd0+0x8
   at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, RuntimeAssembly requestingAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, AssemblyLoadContext assemblyLoadContext) in System.Private.CoreLib.dll:token 0x6004dcf+0x16
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName) in System.Private.CoreLib.dll:token 0x60035d5+0xe
   at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerReferenceInformationProvider.AnalyzerLoadContext.Load(AssemblyName assemblyName) in /_/src/Analyzers/AnalyzerReferenceInformationProvider.cs:line 98
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName) in System.Private.CoreLib.dll:token 0x60035e6+0x20
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName) in System.Private.CoreLib.dll:token 0x60035e3+0x7
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
   at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly) in System.Private.CoreLib.dll:token 0x6004dd0+0x8
   at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, RuntimeAssembly requestingAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, AssemblyLoadContext assemblyLoadContext) in System.Private.CoreLib.dll:token 0x6004dcf+0x16
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName) in System.Private.CoreLib.dll:token 0x60035d5+0xe
   at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerReferenceInformationProvider.AnalyzerLoadContext.Load(AssemblyName assemblyName) in /_/src/Analyzers/AnalyzerReferenceInformationProvider.cs:line 98
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName) in System.Private.CoreLib.dll:token 0x60035e6+0x20
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName) in System.Private.CoreLib.dll:token 0x60035e3+0x7
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
   at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly) in System.Private.CoreLib.dll:token 0x6004dd0+0x8
   at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, RuntimeAssembly requestingAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, AssemblyLoadContext assemblyLoadContext) in System.Private.CoreLib.dll:token 0x6004dcf+0x16
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName) in System.Private.CoreLib.dll:token 0x60035d5+0xe
   at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerReferenceInformationProvider.AnalyzerLoadContext.Load(AssemblyName assemblyName) in /_/src/Analyzers/AnalyzerReferenceInformationProvider.cs:line 98
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName) in System.Private.CoreLib.dll:token 0x60035e6+0x20
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName) in System.Private.CoreLib.dll:token 0x60035e3+0x7
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
   at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly) in System.Private.CoreLib.dll:token 0x6004dd0+0x8
   at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, RuntimeAssembly requestingAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, AssemblyLoadContext assemblyLoadContext) in System.Private.CoreLib.dll:token 0x6004dcf+0x16
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName) in System.Private.CoreLib.dll:token 0x60035d5+0xe
   at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerReferenceInformationProvider.AnalyzerLoadContext.Load(AssemblyName assemblyName) in /_/src/Analyzers/AnalyzerReferenceInformationProvider.cs:line 98
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName) in System.Private.CoreLib.dll:token 0x60035e6+0x20
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName) in System.Private.CoreLib.dll:token 0x60035e3+0x7
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.AspNetCore.Razor.Language, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
   at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly) in System.Private.CoreLib.dll:token 0x6004dd0+0x8
   at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, RuntimeAssembly requestingAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, AssemblyLoadContext assemblyLoadContext) in System.Private.CoreLib.dll:token 0x6004dcf+0x16
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName) in System.Private.CoreLib.dll:token 0x60035d5+0xe
   at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerReferenceInformationProvider.AnalyzerLoadContext.Load(AssemblyName assemblyName) in /_/src/Analyzers/AnalyzerReferenceInformationProvider.cs:line 98
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName) in System.Private.CoreLib.dll:token 0x60035e6+0x20
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName) in System.Private.CoreLib.dll:token 0x60035e3+0x7

@dougbu
Copy link

dougbu commented Apr 30, 2021

I can understand the tool tripping over our C++ projects but that doesn't seem related to the stack trace. Might be another bizarre Razor / Rosly / analyzers interaction here.

Found a more narrow test case:

dotnet format --fix-analyzers warn --no-restore src\Azure\AzureAD\Authentication.AzureAD.UI\src\Microsoft.AspNetCore.Authentication.AzureAD.UI.csproj

results in the same stack trace as above.

Working on traipsing through the many *.csproj files we have to eliminate all that cause dotnet format to crash ☹️

@dougbu
Copy link

dougbu commented Apr 30, 2021

dir -recurse src\*.csproj |% FullName |? {$_ -like '*\src\*\src\*'} |% {if (sls -Quiet '<AddRazorSupportForMvc>true' $_) {echo "Skipping $_"} else {echo $_; dotnet format --fix-analyzers warn --no-restore $_}}

gave me the above output (or something I'm unable to distinguish) for

  • src\Components\Authorization\src\Microsoft.AspNetCore.Components.Authorization.csproj
  • src\Components\Server\src\Microsoft.AspNetCore.Components.Server.csproj
  • src\Components\WebAssembly\Authentication.Msal\src\Microsoft.Authentication.WebAssembly.Msal.csproj
  • src\Components\WebAssembly\WebAssembly.Authentication\src\Microsoft.AspNetCore.Components.WebAssembly.Authentication.csproj
  • src\Framework\App.Ref\src\Microsoft.AspNetCore.App.Ref.csproj
  • src\Framework\App.Runtime\src\Microsoft.AspNetCore.App.Runtime.csproj
  • src\Identity\ApiAuthorization.IdentityServer\src\Microsoft.AspNetCore.ApiAuthorization.IdentityServer.csproj
  • src\Mvc\Mvc\src\Microsoft.AspNetCore.Mvc.csproj
  • src\Mvc\Mvc.Localization\src\Microsoft.AspNetCore.Mvc.Localization.csproj
  • src\Mvc\Mvc.NewtonsoftJson\src\Microsoft.AspNetCore.Mvc.NewtonsoftJson.csproj
  • src\Mvc\Mvc.Razor\src\Microsoft.AspNetCore.Mvc.Razor.csproj
  • src\Mvc\Mvc.Razor.RuntimeCompilation\src\Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.csproj
  • src\Mvc\Mvc.RazorPages\src\Microsoft.AspNetCore.Mvc.RazorPages.csproj
  • src\Mvc\Mvc.TagHelpers\src\Microsoft.AspNetCore.Mvc.TagHelpers.csproj
  • src\Mvc\Mvc.ViewFeatures\src\Microsoft.AspNetCore.Mvc.ViewFeatures.csproj

The skipped projects were

  • src\Azure\AzureAD\Authentication.AzureAD.UI\src\Microsoft.AspNetCore.Authentication.AzureAD.UI.csproj
  • src\Azure\AzureAD\Authentication.AzureADB2C.UI\src\Microsoft.AspNetCore.Authentication.AzureADB2C.UI.csproj
  • src\Identity\UI\src\Microsoft.AspNetCore.Identity.UI.csproj

Checking transitive references to the skipped three in the projects listed above…

@JoeRobich
Copy link
Member Author

@dougbu The issue for dotnet-format is that we still target .NET Core 2.1 and do not have access to the AssemblyDependencyResolver. The SDK packaging for the Razor source generators no longer includes all dependencies in folder and instead relies on loading dependencies via a .deps.json. In the 6.x branch we intend to move to target .NET Core 3.1 which will make the resolver available to us.

@dougbu
Copy link

dougbu commented May 3, 2021

@JoeRobich

we intend to move to target .NET Core 3.1

So, long story short, until that transition, we'll only be able to apply dotnet format in projects that neither use Razor nor reference projects that use Razor❔ That's a fairly large percentage of the dotnet/aspnetcore repo but it doesn't cover enough of Microsoft.AspNetCore.App.Ref or Microsoft.AspNetCore.App.Runtime to be truly useful at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request This issue is requesting an enhancement or new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants