_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.
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.
Hello, would you mind providing a simple repro project so we can investigate further?
Hi Taylor
I just wanted to create one, but I noticed it that with the 16.5 the issue is resolved.
Thanks
Nino
Ah, good to hear. I'll mark this appropriately.
(private comment, text removed)
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
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.
Repro steps:
3. Add the following to `Counter.razor`:
```cshtml
@if (showSomething)
{
<p>Hello World</p>
}
1>------ Build started: Project: BlazorApp_CustomerRepro1, Configuration: Debug Any CPU ------
1>C:\Users\nimullen\source\repos\BlazorApp_CustomerRepro1\BlazorApp_CustomerRepro1\Pages\Counter.razor.cs(10,22,10,35): warning CS0414: The field 'Counter.showSomething' is assigned but its value is never used
1>BlazorApp_CustomerRepro1 -> C:\Users\nimullen\source\repos\BlazorApp_CustomerRepro1\BlazorApp_CustomerRepro1\bin\Debug\netcoreapp3.1\BlazorApp_CustomerRepro1.dll
1>BlazorApp_CustomerRepro1 -> C:\Users\nimullen\source\repos\BlazorApp_CustomerRepro1\BlazorApp_CustomerRepro1\bin\Debug\netcoreapp3.1\BlazorApp_CustomerRepro1.Views.dll
1>Done building project "BlazorApp_CustomerRepro1.csproj".
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
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 @functions
/ @code
. This would technically be fixed by source generators but those are on the cutline for .NET 5.
@NTaylorMullen why is step #2 (set Nullability) required here?
@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.
We're moving this issue to the Next sprint planning
milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.
Most helpful comment
When is this going to be fixed? It's annoying to see those warnings from analyzers.