Open WeihanLi opened 2 years ago
I have the same issue. I am sure it is bound to a source generator.
Did you find any work-around?
I have a stack trace if it helps. (Project build works normaly)
Could not load file or assembly 'Dependency.Of.Source.Generation, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.Assembly.GetTypes()
at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerFinderHelpers.<>c.<LoadAnalyzersAndFixers>b__0_0(Assembly assembly)
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.OfTypeIterator[TResult](IEnumerable source)+MoveNext()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
at System.Collections.Immutable.ImmutableArray.ToImmutableArray[TSource](IEnumerable`1 items)
at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerFinderHelpers.LoadAnalyzersAndFixers(IEnumerable`1 assemblies)
at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerReferenceInformationProvider.GetAnalyzersAndFixers(Project project)
at System.Collections.Immutable.ImmutableDictionary.<>c__DisplayClass9_0`3.<ToImmutableDictionary>b__0(TSource element)
at System.Linq.Utilities.<>c__DisplayClass2_0`3.<CombineSelectors>b__0(TSource x)
at System.Linq.Enumerable.SelectIListIterator`2.MoveNext()
at System.Collections.Immutable.ImmutableDictionary`2.AddRange(IEnumerable`1 items, MutationInput origin, KeyCollisionBehavior collisionBehavior)
at System.Collections.Immutable.ImmutableDictionary`2.AddRange(IEnumerable`1 pairs, Boolean avoidToHashMap)
at System.Collections.Immutable.ImmutableDictionary`2.AddRange(IEnumerable`1 pairs)
at System.Collections.Immutable.ImmutableDictionary.ToImmutableDictionary[TSource,TKey,TValue](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 keyComparer, IEqualityComparer`1 valueComparer)
at System.Collections.Immutable.ImmutableDictionary.ToImmutableDictionary[TSource,TKey,TValue](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerReferenceInformationProvider.GetAnalyzersAndFixers(Solution solution, FormatOptions formatOptions, ILogger logger)
at Microsoft.CodeAnalysis.Tools.Analyzers.AnalyzerFormatter.FormatAsync(Solution solution, ImmutableArray`1 formattableDocuments, FormatOptions formatOptions, ILogger logger, List`1 formattedFiles, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Tools.CodeFormatter.RunCodeFormattersAsync(Solution solution, ImmutableArray`1 formattableDocuments, FormatOptions formatOptions, ILogger logger, List`1 formattedFiles, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Tools.CodeFormatter.FormatWorkspaceAsync(FormatOptions formatOptions, ILogger logger, CancellationToken cancellationToken, String binaryLogPath)
at Microsoft.CodeAnalysis.Tools.FormatCommandCommon.FormatAsync(FormatOptions formatOptions, ILogger`1 logger, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Tools.Commands.FormatAnalyzersCommand.FormatAnalyzersHandler.InvokeAsync(InvocationContext context)
at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass27_0.<<UseVersionOption>b__1>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass25_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__24_0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<<UseDebugDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<<UseExceptionHandler>b__0>d.MoveNext()
Did you find any work-around?
No, I did not find any work-around for now.
Some general thoughts on source generator support in dotnet-format. It may not be obvious but dotnet-format does not build your project or solution. If your project has a project reference that is a source generator, then it will be necessary to dotnet build
that project prior to running dotnet format
on your project or solution. dotnet-format will then try and load the compiled source generator from the projects output folder. If there are any required dependencies they need to be present in the output folder.
I've done a little investigation into the ReservationServer issue and it seems to be falling over trying to load the dependencies. I wonder if it is related to https://github.com/dotnet/docs/pull/25785. I'll have to resume the investigation after the holiday break.
Great thanks for your effort @JoeRobich , while I already had a dotnet build
step before the dotnet format
in the Github Action, and I try to add the <EnableDynamicLoading>true</EnableDynamicLoading>
to my root Directory.Build.props
, but seemed it did not work, thanks for your time and have a nice holiday.
👋 @WeihanLi, I think I have a similar issue, already filed an issue but I guess it is basically the same bug.
Also running into this. This started with the .NET 6 SDK - we had no issues with dotnet-format 5.x.
This happens on projects which use Refit v6.2.16 with .NET 5
and dotnet-format 5.1.250801
(even running dotnet build
beforehand).
I've also ran into this issue while trying to lint a source generator in combination with a background worker. It took some time to investigate this issue but now I have minimal repository that reproduces this issue: https://github.com/MarkusRodler/workertest/runs/8049182548?check_suite_focus=true
Fun fact: Linting works with the old version of dotnet-format as you can see in the workflow run above. I hope you can help us with this issue @JoeRobich 😄
Hm - also having this issue in combination with https://github.com/ChilliCream/graphql-platform/tree/main/src/StrawberryShake CodeGenerators. Please fix!
Referencing the following project: https://github.com/OpenReservation/ReservationServer/tree/e964038039c5dae27c5bc524eb9c018dfd4b1b60
I would not expect this solution to work in its current form. At first glance, errors include:
OpenReservation.Business references a source generator contained in OpenReservation.Database: https://github.com/OpenReservation/ReservationServer/blob/e964038039c5dae27c5bc524eb9c018dfd4b1b60/OpenReservation.Business/OpenReservation.Business.csproj#L13
However, this source generator project contains dependencies which are not provided to the consuming project.
OpenReservation.Database contains a source generator, but does not target netstandard2.0. Source generators are required to target netstandard2.0 (nothing earlier or later).
Referencing the following project: https://github.com/OpenReservation/ReservationServer/tree/e964038039c5dae27c5bc524eb9c018dfd4b1b60
I would not expect this solution to work in its current form. At first glance, errors include:
- OpenReservation.Business references a source generator contained in OpenReservation.Database: https://github.com/OpenReservation/ReservationServer/blob/e964038039c5dae27c5bc524eb9c018dfd4b1b60/OpenReservation.Business/OpenReservation.Business.csproj#L13 However, this source generator project contains dependencies which are not provided to the consuming project.
- OpenReservation.Database contains a source generator, but does not target netstandard2.0. Source generators are required to target netstandard2.0 (nothing earlier or later).
Actually, the source generator does work for me, I changed back to T4 to makes the dotnet format
work in https://github.com/OpenReservation/ReservationServer/commit/7e7f5d7bcb6c7e849a7c24db5eab9cec12a045ad, the commit for SourceGenerator should be https://github.com/OpenReservation/ReservationServer/tree/78dda500c1e93002d53e2c61a3b6591b33b490e3
Describe the bug
When I use the
dotnet format
command to format code, I got some errorsCould not load file or assembly
, it may relate to source generator.To Reproduce
There's a sample Github-Action CI https://github.com/OpenReservation/ReservationServer/runs/4492767423, and the project could be built locally https://github.com/OpenReservation/ReservationServer/tree/78dda500c1e93002d53e2c61a3b6591b33b490e3
Exceptions
Further technical details
dotnet --info