1

After I add the nuget CommunityToolkit.Mvvm version(8.1.0) in my project it gives lots of errors. Most of them are for unhandled exceptions. Here is some examples,

>CSC : warning CS8032: An instance of analyzer CommunityToolkit.Mvvm.SourceGenerators.UnsupportedCSharpLanguageVersionAnalyzer cannot be created from C:\Users\khras\.nuget\packages\communitytoolkit.mvvm\8.1.0\analyzers\dotnet\roslyn4.3\cs\CommunityToolkit.Mvvm.SourceGenerators.dll : Could not load file or assembly 'System.Collections.Immutable, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified..
1>CSC : warning CS8032: An instance of analyzer CommunityToolkit.Mvvm.SourceGenerators.INotifyPropertyChangedGenerator cannot be created from C:\Users\khras\.nuget\packages\communitytoolkit.mvvm\8.1.0\analyzers\dotnet\roslyn4.3\cs\CommunityToolkit.Mvvm.SourceGenerators.dll : Could not load file or assembly 'System.Collections.Immutable, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified..
1>CSC : warning CS8032: An instance of analyzer CommunityToolkit.Mvvm.SourceGenerators.ObservableObjectGenerator cannot be created from C:\Users\khras\.nuget\packages\communitytoolkit.mvvm\8.1.0\analyzers\dotnet\roslyn4.3\cs\CommunityToolkit.Mvvm.SourceGenerators.dll : Could not load file or assembly 'System.Collections.Immutable, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified..
1>CSC : warning CS8032: An instance of analyzer CommunityToolkit.Mvvm.SourceGenerators.ObservableRecipientGenerator cannot be created from C:\Users\khras\.nuget\packages\communitytoolkit.mvvm\8.1.0\analyzers\dotnet\roslyn4.3\cs\CommunityToolkit.Mvvm.SourceGenerators.dll : Could not load file or assembly 'System.Collections.Immutable, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified..
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(75,5): error :
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(75,5): error : Unhandled Exception: System.NotImplementedException: The method or operation is not implemented.
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(75,5): error :    at Microsoft.CodeAnalysis.CommonCompiler.LoggingMetadataFileReferenceResolver.GetHashCode()
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(75,5): error :    at Roslyn.Utilities.Hash.Combine[T](T newKeyPart, Int32 currentKey)
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(75,5): error :    at Microsoft.CodeAnalysis.CompilationOptions.GetHashCodeHelper()
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(75,5): error :    at Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions.GetHashCode()
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(75,5): error :    at System.Collections.Generic.ObjectEqualityComparer`1.GetHashCode(T obj)
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(75,5): error :    at System.Collections.Generic.HashSet`1.InternalGetHashCode(T item)
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(75,5): error :    at System.Collections.Generic.HashSet`1.AddIfNotPresent(T value)
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(75,5): error :    at Microsoft.CodeAnalysis.InputNode`1.UpdateStateTable(Builder graphState, NodeStateTable`1 previousTable, CancellationToken cancellationToken)
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(75,5): error :    at Microsoft.CodeAnalysis.DriverStateTable.Builder.GetLatestStateTableForNode[T](IIncrementalGeneratorNode`1 source)
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(75,5): error :    at Microsoft.CodeAnalysis.TransformNode`2.UpdateStateTable(Builder builder, NodeStateTable`1 previousTable, CancellationToken cancellationToken)
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(75,5): error :    at Microsoft.CodeAnalysis.DriverStateTable.Builder.GetLatestStateTableForNode[T](IIncrementalGeneratorNode`1 source)
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(75,5): error :    at Microsoft.CodeAnalysis.CombineNode`2.UpdateStateTable(Builder graphState, NodeStateTable`1 previousTable, CancellationToken cancellationToken)
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(75,5): error :    at Microsoft.CodeAnalysis.DriverStateTable.Builder.GetLatestStateTableForNode[T](IIncrementalGeneratorNode`1 source)
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(75,5): error :    at Microsoft.CodeAnalysis.TransformNode`2.UpdateStateTable(Builder builder, NodeStateTable`1 previousTable, CancellationToken cancellationToken)

I've tried building the project with uninstalling the nuget package and it works fine. The strange thing is I can not find the packages in my solution explorer after I install the nuget. enter image description here

I've tried with cleaning the project, restarting VS 2022 and restarting my pc. But it does not seems to work. Any help will be greatly appriciated.

If you need more information just ask in the comment.

Update: I've found another error in the Analyzer,

The source generator features from the MVVM Toolkit require consuming projects to set the C# language version to at least C# 8.0. Make sure to add <LangVersion>8.0</LangVersion> (or above) to your .csproj file.

But the Language version is set to 10.

  • You can expand the `net6.0-android`, `net6.0-ios`, etc., dependencies by clicking the arrows. Does the package appear then? Due to multi-targeting, the dependencies are listed per target platform. – Julian Jan 19 '23 at 16:43
  • I do not see them @ewerspej – Khandakar Rashed Hassan Jan 19 '23 at 16:50
  • Did you get any error messages when installing the nuget? – Julian Jan 19 '23 at 17:08
  • 1
    I do not. It is showing as installed in NuGet explorer. But I've found the packages under dependency. Thank you. – Khandakar Rashed Hassan Jan 19 '23 at 17:11
  • Can you show how you're using the Source Generators? – Julian Jan 19 '23 at 17:18
  • Hi @ewerspej so I've discovered a new error. In the Analyzer section, it gives me an Unsupported C# version error. Do you know how can I set the C# version? – Khandakar Rashed Hassan Jan 19 '23 at 17:24
  • Strange. The C# version by default depends on the type of project and the platform target. Since you're dealing with .NET 6.0, it shouldn't even be an issue. Are you referencing any .NET Framework projects? How many projects are in your solution and are there other dependencies that might potentially be incompatible. – Julian Jan 19 '23 at 18:30
  • 4
    I have to downgrade to 8.0 and it is working fine. Don't know what is the problem with 8.1.0. – Khandakar Rashed Hassan Jan 19 '23 at 20:46
  • Have you tried upgrading your project to use .NET 7.0? I've been using the 8.1.0 previews with MAUI and .NET 7.0 without problems so far. It would be strange if the recently released 8.1.0 version had this kind of problem all of the sudden, but I'll investigate this soon. – Julian Jan 19 '23 at 22:14
  • Exactly the same problems for me, different .NET versions (6.0, core 3.1), all problematic and problems resolved when uninstalling the toolkit. Downgrade to 8.0 does the job, thanks a lot @KhandakarRashedHassan! (y) – benzhi Apr 18 '23 at 20:50

0 Answers0