Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObservablePropertyAttribute on a field: avoid CS0169? #375

Closed
chucker opened this issue Aug 10, 2022 · 6 comments · Fixed by #551
Closed

ObservablePropertyAttribute on a field: avoid CS0169? #375

chucker opened this issue Aug 10, 2022 · 6 comments · Fixed by #551
Labels
mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit unable to reproduce ✖️ A reported issue that couldn't be reproduced

Comments

@chucker
Copy link

chucker commented Aug 10, 2022

I made a simple INPC property like so:

[ObservableProperty]
private bool _IsReadOnly;

As expected, I can now bind to IsReadOnly in XAML. Great! However, VS now shows me a warning:

Severity    Code    Description Project File    Line    Category    Suppression State
Warning CS0169  The field 'MyViewModel._IsReadOnly' is never used MyProject   MyViewModel.cs  148 Build   Active

Makes sense; it doesn't understand that the field exists only for the generated code. However:

  1. is that the expected behavior?
  2. even if I wrap the field in #warning pragma disable CS0169, the warning doesn't go away. Am I missing something?
@chucker
Copy link
Author

chucker commented Aug 10, 2022

(Hm, maybe https://github.com/CommunityToolkit/dotnet is the more appropriate repo? Not sure.)

@Sergio0694 Sergio0694 transferred this issue from CommunityToolkit/MVVM-Samples Aug 10, 2022
@Sergio0694
Copy link
Member

Mmh is your code actually compiling? That field name is incorrect, as it starts with an uppercase character 🤔

@Sergio0694 Sergio0694 added needs author feedback 📝 This issue or PR needs a reply from the author mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit labels Aug 10, 2022
@chucker
Copy link
Author

chucker commented Aug 10, 2022

Mmh is your code actually compiling? That field name is incorrect, as it starts with an uppercase character 🤔

I tried with the variants isReadyOnly and _isReadOnly as well. In all three cases, the generated code looks correct; both its set and get point to my field.

So I don't think that's the issue.

However, my use of the .NET 5 SDK (due to some regressions in 6.0) could be it?

{
	"sdk": {
		"version": "5.0.400"
	}
}

@michael-hawker
Copy link
Member

@chucker which version of the MVVM package are you using? If it's 8.0, I'm pretty sure you have to be building with .NET 6.

@chucker
Copy link
Author

chucker commented Aug 15, 2022

It is indeed 8.0. Other than the compiler warning, it seems to work fine (at least for [ObservableProperty]).

If someone can confirm that this is indeed a known issue in the .NET 5 SDK, then fair enough.

@Sergio0694 Sergio0694 added unable to reproduce ✖️ A reported issue that couldn't be reproduced and removed needs author feedback 📝 This issue or PR needs a reply from the author labels Jan 1, 2023
@Sergio0694
Copy link
Member

Couldn't repro this, but I've added one more unit test to cover this too in a PR. Thank you! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit unable to reproduce ✖️ A reported issue that couldn't be reproduced
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants