question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Required references did not load

See original GitHub issue

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).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
felschrcommented, 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.

0reactions
vmandiccommented, 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>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Visual Studio doesn't load project references
When I open the properties tab for a system reference, the Path field is empty, and so the Resolved field is False ......
Read more >
What To Do if You Have No References for a Job Application
You may find yourself in a situation where you need to provide references but don't have any professional experience or work contacts.
Read more >
Troubleshoot broken references - Visual Studio
If projects are shared on different computers, some references might not be found when a component is located in a different directory.
Read more >
External reference (xref) file is missing or unresolved in ...
When opening a drawing in AutoCAD products, the following message appears and some or all the referenced files are not loaded, or show...
Read more >
When and how to include references on a resume
This in-depth guide teaches you when to include references on a resume, and when NOT to use them.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found