Repository navigation
Labels
BugProduct bug (most likely)regressionstatus: This issue is a regression from a previous build or release
Description
Version 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
Reacted by Glenn, Anton Rau, Nikita Timofeev, pedro-elipse, elsupermesq, Yaroslav Bugaria, Julian Verdurmen, Jochem, JianpingCAI, jpsaccount and 8 more
Reacted by Nirmal Guru
Metadata
Metadata
Assignees
Labels
BugProduct bug (most likely)regressionstatus: This issue is a regression from a previous build or release
Activity
RikkiGibson commentedon Jul 12, 2022
If you build your project from the developer command prompt and pass
-blit should produce a binary log which you can use to confirm that:jamiehankins commentedon Jul 13, 2022
@RikkiGibson
Wow, first I've seen of this tool. There's an insane amount of info, but I can't seem to find that needle in this haystack.
Here's the output from building my tiny test project in case you have a better idea of where in there to look.
msbuild.zip
RikkiGibson commentedon Jul 13, 2022
It's in the Csc task which contains the build errors, under CommandLineArguments
In this case the paths appear to be:
C:\Users\jamie.hankins\.nuget\packages\communitytoolkit.mvvm\7.1.2\analyzers\dotnet\cs\CommunityToolkit.Mvvm.SourceGenerators.dllC:\Users\jamie.hankins\.nuget\packages\communitytoolkit.mvvm\7.1.2\analyzers\dotnet\cs\CommunityToolkit.Mvvm.SourceGenerators.dllIn other words, the two paths are exactly the same. It's odd that msbuild would do that, It feels like the compiler should be modified to give a diagnostic and/or dedupe the duplicate generators. I'll have to look more closely later to confirm that and determine a root cause.
k-u-s commentedon Jul 13, 2022
Got similar problem after updating from 6.0.6 to 6.0.7 (sdk 6.0.301 to 6.0.302) but with code ganareted via CsWin32
Minimal repro crated by WPF apllication template from Visual studio 2022 and adding mentioned nuget:
WpfApp.Issue62582.zip
Moving code generation to separate class library fixes issue.
dotnet --info
C:\WpfApp.Issue62582>dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.302
Commit: c857713418
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22000
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\6.0.302\
global.json file:
Not found
Host:
Version: 6.0.7
Architecture: x64
Commit: 0ec02c8c96
.NET SDKs installed:
3.1.400 [C:\Program Files\dotnet\sdk]
5.0.103 [C:\Program Files\dotnet\sdk]
6.0.201 [C:\Program Files\dotnet\sdk]
6.0.301 [C:\Program Files\dotnet\sdk]
6.0.302 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Download .NET:
https://aka.ms/dotnet-download
Learn about .NET Runtimes and SDKs:
https://aka.ms/dotnet/runtimes-sdk-info
dotnet build
C:\WpfApp.Issue62582>dotnet build Microsoft (R) Build Engine version 17.2.0+41abc5629 for .NET Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
Restored C:\WpfApp.Issue62582\WpfApp.Issue62582.csproj (in 221 ms).
C:\WpfApp.Issue62582\Microsoft.Windows.CsWin32\Microsoft.Windows.CsWin32.SourceGenerator\Windows.Win32.WINDOW_STYLE.g.cs(23,15): error CS0101: The namespace 'Windows.Win32.UI.WindowsAndMe
ssaging' already contains a definition for 'WINDOW_STYLE' [C:\WpfApp.Issue62582\WpfApp.Issue62582_uddecyia_wpftmp.csproj]
Build FAILED.
C:\WpfApp.Issue62582\Microsoft.Windows.CsWin32\Microsoft.Windows.CsWin32.SourceGenerator\Windows.Win32.WINDOW_STYLE.g.cs(23,15): error CS0101: The namespace 'Windows.Win32.UI.WindowsAndMe
ssaging' already contains a definition for 'WINDOW_STYLE' [C:\WpfApp.Issue62582\WpfApp.Issue62582_uddecyia_wpftmp.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:02.94
DingpingZhang commentedon Jul 13, 2022
This is a generic problem that affects all source generator projects.
It seems to occur only when referenced by the nuget package, If referenced in the following (manual reference), there will be no problem, so the test cases within the source generator project are normal.
Tum4ik commentedon Jul 13, 2022
I also have faced the same problem with Refit.
tan-force commentedon Jul 13, 2022
I uninstalled VS 17.2.6 and installed 17.2.5 that used to work. It doesn't anymore :-( Still the same error.
glennawatson commentedon Jul 13, 2022
@tan-force seems to be related to dotnet 6.0.7 so you may have to uninstall that version
tan-force commentedon Jul 13, 2022
Yes! Uninstalled dotnet 6.0.7, and now it works. Thank you.
Tum4ik commentedon Jul 13, 2022
You still can use the latest version of Visual Studio. Here is a workaround that works for me:
global.jsonfile to the root of your solution (where .sln file is located)global.json:{ "sdk": { "version": "6.0.301", "rollForward": "disable" } }aahz16384 commentedon Jul 13, 2022
Source generators still working in actual VS2022 preview.
LadislavLang commentedon Jul 13, 2022
I've the same problem in latest preview (17.3.0 Preview 3.0)
69 remaining items
rasyidf commentedon Sep 1, 2022
Still occurred in latest .NET 7 Preview
Gakk commentedon Sep 2, 2022
Thanks @rainersigwald for this solution. It looks like it fixed the issue with the duplicate analyzers 🙂👍
Unfortunately it also looks like it may have an unattended side effect 🤔
I have a WPF application, and it has a constructor with a parameter:
MSBuild then generates a partial class with
Main(), but this now uses a constructor without parameters - which in my case does not exist:Resulting in:
error CS7036: There is no argument given that corresponds to the required formal parameter 'splash' of 'App.App(SplashScreen)'
Anyone other that has experienced this with the workaround? Or also has a constructor with a parameter that is not affected by this workaround, and can confirm that this issue must come from something else?
I experienced this issue with the generators when switching from legacy project file to SDK style project file, so my error might be related to something else as well...
ThomasGoulet73 commentedon Sep 2, 2022
Hey @Gakk, I doubt that your issue is related to analyzers/generators.
This is likely the cause:
I experienced this issue with the generators when switching from legacy project file to SDK style project fileWithout a repro I can only speculate but it looks like you use your own Main entry point instead of the generated App.Main and pass a SplashScreen to the constructor of App. In your legacy project file, App.xaml was probably included as
Pageinstead ofApplicationDefinitionwhich meant that App.Main was never generated. If you do not use the generated App.Main, you need to set the MSBuild propertyEnableDefaultApplicationDefinitionto false in your project. If this does not fix your issue, please open a new Github issue without a repro project since it is probably unrelated to this one.Thanks.
Workaround for dotnet/wpf#6792
ThomasGoulet73 commentedon Sep 13, 2022
This issue should now be fixed in .Net SDK 6.0.9 released today.
ecxdev commentedon Sep 15, 2022
I had the same problem today! How to fix it?
`Version: 6.0.401
Commit: 0906eae6f8
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19044
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\6.0.401\
global.json file:
Not found
Host:
Version: 6.0.9
Architecture: x64
Commit: 163a63591c
.NET SDKs installed:
6.0.401 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]`
virzak commentedon Sep 15, 2022
@ecxdev If you have .NET 7 preview-7 upgrade to .NET 7 RC-1 and it should fix it. Either that or specify version 6 in global.json
ecxdev commentedon Sep 15, 2022
The project was rebuilt successfully when I deleted this previously inserted code from the project file.
Revert "Apply temporary fix for dotnet/wpf#6792"
Revert "Apply temporary fix for dotnet/wpf#6792"
[Build] Workaround for dotnet/wpf#6792
Work around dotnet/wpf#6792
Merge branch 'dev' into QuickSizeAdjust & Work around dotnet/wpf#6792
Duplicate analyzer issue fixes