Home > OS >  How to solve .NET7 csproj issues with compli
How to solve .NET7 csproj issues with compli

Time:12-24

I'm using Visual Studio Enterprise Version 17.3.3. When I start VS and open/create a .NET 7 project, it gives me the following errors after opening any .cs file: enter image description here here is the log:

===================== 2022-12-21 10:27:35 Recoverable Microsoft.VisualStudio.ProjectSystem.Query.QueryExecutionException: Index was outside the bounds of the array. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array. at Microsoft.CodeAnalysis.NodeStateTable1.Single() at Microsoft.CodeAnalysis.CombineNode2.UpdateStateTable(Builder graphState, NodeStateTable1 previousTable, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.DriverStateTable.Builder.GetLatestStateTableForNode[T](IIncrementalGeneratorNode1 source) at Microsoft.CodeAnalysis.TransformNode2.UpdateStateTable(Builder builder, NodeStateTable1 previousTable, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.DriverStateTable.Builder.GetLatestStateTableForNode[T](IIncrementalGeneratorNode1 source) at Microsoft.CodeAnalysis.CombineNode2.UpdateStateTable(Builder graphState, NodeStateTable1 previousTable, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.DriverStateTable.Builder.GetLatestStateTableForNode[T](IIncrementalGeneratorNode1 source) at Microsoft.CodeAnalysis.TransformNode2.UpdateStateTable(Builder builder, NodeStateTable1 previousTable, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.DriverStateTable.Builder.GetLatestStateTableForNode[T](IIncrementalGeneratorNode1 source) at Microsoft.CodeAnalysis.BatchNode1.UpdateStateTable(Builder builder, NodeStateTable1 previousTable, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.DriverStateTable.Builder.GetLatestStateTableForNode[T](IIncrementalGeneratorNode1 source) at Microsoft.CodeAnalysis.CombineNode2.UpdateStateTable(Builder graphState, NodeStateTable1 previousTable, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.DriverStateTable.Builder.GetLatestStateTableForNode[T](IIncrementalGeneratorNode1 source) at Microsoft.CodeAnalysis.CombineNode2.UpdateStateTable(Builder graphState, NodeStateTable1 previousTable, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.DriverStateTable.Builder.GetLatestStateTableForNode[T](IIncrementalGeneratorNode1 source) at Microsoft.CodeAnalysis.TransformNode2.UpdateStateTable(Builder builder, NodeStateTable1 previousTable, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.DriverStateTable.Builder.GetLatestStateTableForNode[T](IIncrementalGeneratorNode1 source) at Microsoft.CodeAnalysis.CombineNode2.UpdateStateTable(Builder graphState, NodeStateTable1 previousTable, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.DriverStateTable.Builder.GetLatestStateTableForNode[T](IIncrementalGeneratorNode1 source) at Microsoft.CodeAnalysis.TransformNode2.UpdateStateTable(Builder builder, NodeStateTable1 previousTable, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.DriverStateTable.Builder.GetLatestStateTableForNode[T](IIncrementalGeneratorNode1 source) at Microsoft.CodeAnalysis.CombineNode2.UpdateStateTable(Builder graphState, NodeStateTable1 previousTable, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.DriverStateTable.Builder.GetLatestStateTableForNode[T](IIncrementalGeneratorNode1 source) at Microsoft.CodeAnalysis.CombineNode2.UpdateStateTable(Builder graphState, NodeStateTable1 previousTable, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.DriverStateTable.Builder.GetLatestStateTableForNode[T](IIncrementalGeneratorNode1 source) at Microsoft.CodeAnalysis.TransformNode2.UpdateStateTable(Builder builder, NodeStateTable1 previousTable, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.DriverStateTable.Builder.GetLatestStateTableForNode[T](IIncrementalGeneratorNode1 source) at Microsoft.CodeAnalysis.SourceOutputNode1.UpdateStateTable(Builder graphState, NodeStateTable1 previousTable, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.DriverStateTable.Builder.GetLatestStateTableForNode[T](IIncrementalGeneratorNode1 source) at Microsoft.CodeAnalysis.SourceOutputNode1.AppendOutputs(IncrementalExecutionContext context, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.GeneratorDriver.UpdateOutputs(ImmutableArray1 outputNodes, IncrementalGeneratorOutputKind outputKind, Builder generatorRunStateBuilder, CancellationToken cancellationToken, Builder driverStateBuilder) at Microsoft.CodeAnalysis.GeneratorDriver.RunGeneratorsCore(Compilation compilation, DiagnosticBag diagnosticsBag, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.GeneratorDriver.RunGenerators(Compilation compilation, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.<FinalizeCompilationAsync>d__39.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.<BuildFinalStateFromInProgressStateAsync>d__36.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.<BuildCompilationInfoAsync>d__32.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.<GetOrBuildCompilationInfoAsync>d__31.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.<GetCompilationSlowAsync>d__29.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.VisualStudio.ProjectSystem.Properties.StartupObjectsEnumGenerator.<GetListedValuesAsync>d__8.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.VisualStudio.ProjectSystem.PropertyPages.PageDynamicEnumProperty.<CreateAdmissibleValuesAsync>d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.VisualStudio.ProjectSystem.VS.Query.SupportedValueDataProducer.<CreateSupportedValuesAsync>d__1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.VisualStudio.ProjectSystem.VS.Query.QueryDataFromProviderStateProducerBase1.d__0.MoveNext() --- End of inner exception stack trace --- at Microsoft.VisualStudio.ProjectSystem.Query.QueryExecution.QuerySubscription1.<RunQueryOnceAsync>d__9.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.VisualStudio.ProjectSystem.Query.QueryExecution.QuerySubscription1.<>c__DisplayClass8_0.<b__0>d.MoveNext()

When I try to go to project properties, this log is shown instead of the default items. IntelliSense doesn't work and VS treats my .cs files like normal text files. There is only the coloring feature for my codes. The projects however compile successfully. If I add <EnableDefaultCompileItems>false</EnableDefaultCompileItems> to the csproj file and then import the files manually, everything is back to normal. But it's not possible because I have a solution that is recently upgraded to .NET 7 and doesn't work either. There are many projects and items in this solution so I can not (and rather not to) import every file manually.
My csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web">
    <PropertyGroup>
        <TargetFramework>net7.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
    </PropertyGroup>
</Project>

CodePudding user response:

As written in this blog, .NET 7 is part of Visual Studio 2022 17.4.

So if you need .Net 7, please update to the latest version.

Like 17.4

If you're after something stable, you can use .Net 6.

  • Related