Skip to content
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

Required references did not load #854

Closed
felschr opened this issue Nov 2, 2020 · 5 comments
Closed

Required references did not load #854

felschr opened this issue Nov 2, 2020 · 5 comments
Labels
Needs More Info This issue needs additional details to be actionable

Comments

@felschr
Copy link

felschr commented Nov 2, 2020

I get a lot of errors like these:

Required references did not load for [project name] or referenced project. Run `dotnet restore` prior to formatting.

Running dotnet restore doesn't help, though. This happens for a lot of the projects in my solution, not all of them, though.

I'm running v5.0.152601 on Linux (NixOS).

@JoeRobich JoeRobich added the Needs More Info This issue needs additional details to be actionable label Nov 2, 2020
@JoeRobich
Copy link
Member

@felschr Sorry you are running into this. I haven't encountered this issue myself. Can you share a project with us that repros this behavior?

@felschr
Copy link
Author

felschr commented Nov 2, 2020

Unfortunately none of the projects are open source.
I'm gonna investigate a little further tomorrow and maybe I can create a sample project to reproduce the issue.

@felschr
Copy link
Author

felschr commented Nov 3, 2020

Upgrading the dotnet SDK from 3.1.102 to 3.1.402 ultimately resolved the issue for me.

If it's of any interest I was able to reproduce the issue with SDK 3.1.102 using @canton7's test repo which they shared in #584 (that issue also seems to be resolved by updating the SDK).

@ghost ghost closed this as completed Sep 28, 2021
@ghost
Copy link

ghost commented Sep 28, 2021

Closing this issue as we've seen no reply to the request for more information. If you are able to get the requested information, please add it to the issue and we will retriage it.

@vmandic
Copy link

vmandic commented Oct 27, 2022

I am facing this issue after upgrading from .netcoreapp3.1 to net6.0 TFM (SDK 6.0.401)

(dotnet format also changed its API... so the previous CLI command does not work so one has to adapt to the breaking change)

I ran dotnet restore multiple times even with -f flag.

...
Required references did not load for MyProjectREDACTED(net6.0) or referenced project. Run `dotnet restore` prior to formatting.

Unhandled exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load type 'Microsoft.CodeAnalysis.IIncrementalGenerator' from assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Could not load type 'Microsoft.CodeAnalysis.SourceProductionContext' from assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Could not load type 'Microsoft.CodeAnalysis.SourceProductionContext' from assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Could not load type 'Microsoft.CodeAnalysis.SourceProductionContext' from assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
   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) in /_/src/Analyzers/AnalyzerFinderHelpers.cs:line 18
   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 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)
   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) 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.GetExitCodeAsync(Object value, InvocationContext context)
   at System.CommandLine.Invocation.ModelBindingCommandHandler.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()
System.TypeLoadException: Could not load type 'Microsoft.CodeAnalysis.IIncrementalGenerator' from assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
System.TypeLoadException: Could not load type 'Microsoft.CodeAnalysis.SourceProductionContext' from assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
System.TypeLoadException: Could not load type 'Microsoft.CodeAnalysis.SourceProductionContext' from assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
System.TypeLoadException: Could not load type 'Microsoft.CodeAnalysis.SourceProductionContext' from assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
error Command failed with exit code 1.

Any ideas anyone... I get the same issue when I target my referenced libraries to TFM net6.0

My repo root global.json targets 3.1.416, but the one on the project targets 6.0.401, I run dotnet format from repo root. I am trying to gradually upgrade projects but this is hard to pass...

In the target csproj I added the nugets the internet advises... but no help:

    <PackageReference Include="Microsoft.CodeAnalysis" Version="4.3.1" />
    <PackageReference Include="Microsoft.CodeAnalysis.Compilers" Version="4.3.1" />
    <PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="4.3.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Info This issue needs additional details to be actionable
Projects
None yet
Development

No branches or pull requests

3 participants