-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Field used in blazor component shown as "value assigned but never used" #20137
Comments
Repro steps:
public partial class Counter
{
private bool showSomething = false;
}
@if (showSomething)
{
<p>Hello World</p>
}
This looks to be an issue with how we generate the skeletons of our Blazor files in our pre-build step because that pre-build step removes all Razor content other than what's in |
@NTaylorMullen why is step #2 (set Nullability) required here? |
Copy and paste error. It isn't. |
This has not been resolved. If you declare a string variable in the code behind (.razor.cs) and assign it in the .razor file you will get the warning. |
For those who suffers from this strange phenomenon will please take a look at: https://stackoverflow.com/questions/61427520/separate-code-file-in-blazor-gives-bogus-warning-messages |
This should be fixed, but when I saw in one of the associated issues a suggestion to go back to using inheritance instead of partial classes, I decided to take a half step and just make these properties "protected" instead of "private". The compiler doesn't complain about protected properties not being read because it doesn't know what you will do with them in a child class. This workaround isn't a solution though because it takes away the needed check for variables that you declare and actually never use. |
When is this going to be fixed? It's annoying to see those warnings from analyzers. |
Another work around is to make fields into properties. At least for me for properties the reference is calculated correctly. |
Thanks for contacting us. |
Thanks for contacting us. |
Resolved as part of the source generator work. |
@pranavkm Last I tried this, it still repros even with source generators in place. I think there's still some work that we need to do here. See https://github.com/captainsafia/TestPartialClassAssignment. |
This issue has been moved from a ticket on Developer Community.
I have a blazor project with nullable enabled. Here I get loads of warnings for fields who VS thinks are assigned but never used. But when I search for references (see attachement) you can see that they are used in the blazor component and that VS actuall does figure out that this is a reference to the field.
Original Comments
Visual Studio Feedback System on 3/11/2020, 08:26 PM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Taylor Mullen [MSFT] on 3/18/2020, 11:09 AM:
Hello, would you mind providing a simple repro project so we can investigate further?
Nino Padrutt on 3/18/2020, 02:25 PM:
Hi Taylor
I just wanted to create one, but I noticed it that with the 16.5 the issue is resolved.
Thanks
Nino
Taylor Mullen [MSFT] on 3/18/2020, 02:29 PM:
Ah, good to hear. I'll mark this appropriately.
Nino Padrutt on 3/18/2020, 02:37 PM:
(private comment, text removed)
Nino Padrutt on 3/25/2020, 04:33 AM:
Hi Taylor
I saw that this issue is still marked as resolved. Seeing my last comment and the example project this is so far not the case.
Thanks
Nino
Original Solutions
Visual Studio Feedback System solved on 3/18/2020, 02:29 PM, 0 votes:
A fix for this issue has been released! Install the most recent release from https://visualstudio.microsoft.com/downloads/. Thank you for providing valuable feedback which has helped improve the product.
The text was updated successfully, but these errors were encountered: