Visual Studio 17.2.6 Breaks CommunityToolkit.Mvvm
See original GitHub issueVersion Used: 17.2.6
Steps to Reproduce:
- Create a WPF exe project targeting
net6.0-windows
- Reference CommunityToolkit.Mvvm like so:
<PackageReference Include="CommunityToolkit.Mvvm" Version="7.1.2" />
- Create a simple class inheriting from
ObservableObject
, like so:
using CommunityToolkit.Mvvm.ComponentModel;
namespace ObservablePropertyTest
{
public partial class TestVM : ObservableObject
{
[ObservableProperty]
private string _testString = string.Empty;
}
}
Expected Behavior: In 17.2.5, it built and ran fine.
Actual Behavior:
Rebuild started...
1>------ Rebuild All started: Project: ObservablePropertyTest, Configuration: Debug Any CPU ------
Restored C:\git\ObservablePropertyTest\ObservablePropertyTest.csproj (in 2 ms).
1>C:\git\ObservablePropertyTest\CommunityToolkit.Mvvm.SourceGenerators\CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator\__KnownINotifyPropertyChangedOrChangingArgs.cs(12,27,12,70): error CS0101: The namespace 'CommunityToolkit.Mvvm.ComponentModel.__Internals' already contains a definition for '__KnownINotifyPropertyChangedOrChangingArgs'
1>C:\git\ObservablePropertyTest\CommunityToolkit.Mvvm.SourceGenerators\CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator\__KnownINotifyPropertyChangedOrChangingArgs.cs(7,6,7,51): error CS0579: Duplicate 'global::System.CodeDom.Compiler.GeneratedCode' attribute
1>C:\git\ObservablePropertyTest\CommunityToolkit.Mvvm.SourceGenerators\CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator\__KnownINotifyPropertyChangedOrChangingArgs.cs(8,6,8,52): error CS0579: Duplicate 'global::System.Diagnostics.DebuggerNonUserCode' attribute
1>C:\git\ObservablePropertyTest\CommunityToolkit.Mvvm.SourceGenerators\CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator\__KnownINotifyPropertyChangedOrChangingArgs.cs(9,6,9,69): error CS0579: Duplicate 'global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage' attribute
1>C:\git\ObservablePropertyTest\CommunityToolkit.Mvvm.SourceGenerators\CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator\__KnownINotifyPropertyChangedOrChangingArgs.cs(10,6,10,51): error CS0579: Duplicate 'global::System.ComponentModel.EditorBrowsable' attribute
1>C:\git\ObservablePropertyTest\CommunityToolkit.Mvvm.SourceGenerators\CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator\__KnownINotifyPropertyChangedOrChangingArgs.cs(11,6,11,29): error CS0579: Duplicate 'global::System.Obsolete' attribute
1>C:\git\ObservablePropertyTest\CommunityToolkit.Mvvm.SourceGenerators\CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator\ObservablePropertyTest.TestVM.cs(12,23,12,33): error CS0102: The type 'TestVM' already contains a definition for 'TestString'
1>Done building project "ObservablePropertyTest_yynlzhol_wpftmp.csproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
It appears that somehow the CommunityToolkit.Mvvm source generators are being run twice.
If you create a WPF class library, things work fine. They’re only broken in a WPF app.
Here is my test project: ObservablePropertyTest.zip
Issue Analytics
- State:
- Created a year ago
- Reactions:19
- Comments:57 (9 by maintainers)
Top Results From Across the Web
MVVM Toolkit error MVVMTK0008 - .NET Community Toolkit
While updating the C# language version will generally work with no issues, as the compiler has to be resilient to missing types and...
Read more >VS2017 Pro v 15.9.53 c# .net 4.7.2 After Adding ...
I am trying to learn how to use the Microsoft CommunityToolkit.mvvm for a work project. I am building the project via VS2017 Right...
Read more >Support Center
Hello,. According to Visual Studio 17.2.6 Breaks CommunityToolkit.Mvvm #6792 and Fix build when using source generators coming from NuGet ...
Read more >Issue with Resharper, .NET Core 6 and MVVM Community ...
Hi. I am getting lots of errors on a project which uses WPF, the MVVM Community Toolkit and .NET Core 6. The issues...
Read more >CommunityToolKit 8.0 컴파일 에러가 납니다. - 닷넷데브
Visual Studio 17.2.6 Breaks CommunityToolkit.Mvvm. opened 10:50PM - 12 Jul 22 UTC. closed 04:51PM - 14 Jul 22 UTC.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For a workaround @ThomasGoulet73 I tend to prefer @jlaanstra’s from https://github.com/dotnet/wpf/pull/6680#issuecomment-1183552170 with a small modification to use MSBuild engine functionality instead of a task:
You still can use the latest version of Visual Studio. Here is a workaround that works for me:
global.json
file to the root of your solution (where .sln file is located)global.json
: