Issue with Resharper, .NET Core 6 and MVVM Community Toolkit on WPF
Hi
I am getting lots of errors on a project which uses WPF, the MVVM Community Toolkit and .NET Core 6. The issues all come from Resharper, the Build itself runs fine. Here's an image:
All the issues I get are related to the code generators inside the MVVM Toolkit. Basically the idea is to create a ViewModel through annotations.
All those issues go away if I close Visual Studio, then open it back up. Or to be more exact, Resharper shows the same issues after restarting, then performs an analyze process and after that they are gone. Here is the result after doing so:
I didn't change a single line of code, the warnings are expected and are ok. This appears to work a few minutes fine, but at some point suddenly the errors will start to appear again which makes it quite tedious to the point where I will need to disable Resharper or restart Visual Studio (can be a minute, can be 10 minutes).
Once the errors appear, I have tried to click the "reanalyze all files" button but this doesn't make the errors go away. Sometimes, it helps when I click "Clean Build" but usually it doesn't.
Is there anything I can do to trigger Resharper to re-analyze the files like it would do on a Visual Studio start? I am quite sure that this is an issue with the generated files. I am on Visual Studio 2022 17.4.2 and my Resharper Version is 2022.3.2.
Please sign in to leave a comment.
Now I got a similar, but different issue:
It appears that Resharper chokes on the following code part:
I tried to comment out the NotifyCanExecutedChangedFor line and the resharper analyzer got the correct results. This is the only time I make use of the NotifyCanExecuteChangedFor annotation. Maybe it is a combination with the nameof keyword. The RelayCommand SearchCommand is automatically generated from the following function
If I uncomment the above line, Resharper will start yielding warnings which are not ok, suddenly there are 102 warnings which have no reason to be there.
e.g. Resharper complains about a "Method SearchInductors is never used" which is definitely wrong, it is used from the View as relay command SearchInductorsCommand. Apparently the generated files are ignored regarding commands now.
Restarted Visual Studio and the erroneous warnings are gone, only the relevant warnings remain.
Again something funny: One of the errors is now: Ambiguous reference
2 methods in the same class with the same name. If Resharper was right here this should in any case break the build, but the build is fine.
thank you for contacting us.
Please try to install our EAP build from here: https://www.jetbrains.com/resharper/nextversion/#section=windows and check the result.
Thank you!
Hi Olga
It appears that the issue is gone (for now).
But I am now getting the errors from the thread below on a different project:
https://resharper-support.jetbrains.com/hc/en-us/community/posts/360003487280-Warnings-about-all-methods-that-start-with-Get-
Not quite sure why a method name which starts with "Get" should be an issue. Disabling the option you noted in the thread above made the issue go away, but you should look into that before it leaves EAP.
Well, did some work on the project today and Resharper has started acting up again with all kinds of errors ... 81 errors in 3 files .. the build itself succeeds without any errors or warnings.
could you please turn off follow option: ReSharper | Options | Environment | General | Read solution model directly and check how it works for you?
Thank you!
On R# 2022.3.2 and seeing that [ObservableProperty] is not handled correctly. Anywhere I have a field decorated with the [ObservableProperty] attribute and it is a reference type, if I check it for null I get red squiggles saying "Expression is always false" and any code within that conditional block will be grayed out saying that the "Code is heuristically unreachable". This is obviously not true.
Similarly, if I assign null to a reference type field decorated with said attribute, I get the "Possible 'null' assignment to non-nullable entity". Code builds and executes fine.
EDIT: It appears the toolkit's generated source always enables #nullable, regardless of context (I'm in a project that has not yet adopted it). If I wrap [ObservableProperty] equipped reference-type field definitions within `#nullable enable` and `#nullable disable` directives and go ahead and add the question marks this removes the errors as well. But either way it compiles/runs fine.
It took me a while to get back to the project. Yet, the results are unsatisfactory: Changing the option mentioned above I had already tried before due to another thread but it didn't really change a thing. Instead, with the EAP release I get other problems as well, sometimes Exceptions from Resharper pop up so it's basically not useable for me on a daily basis.
The only thing in common is that restarting Visual Studio solves the issue (for a while).
thank you for the answer.
Is it possible to send us a sample project where we can reproduce the issue?
Thank you!
Hi Olga,
I built a sample project and uploaded it here: Upload id: 2023_03_08_KW4GnGrbfPgkXR14gEBqdV (file: wpfapp1.zip)
In the file MainWindowViewModel you can find 2 methods (Dummy1, Dummy2). An an example, for me the errors started to appear when I changed the signature from public to private. Suddenly I got errors for the properties which I didn't touch. Building the project still works.
I am not sure if this is reproducable but for me it can be reproduced as soon as I start adding other properties, changing the method signatures and so on. It might take up to 10min until an error pops up.
thank you for the sample project.
I've tried to reproduce the issue but no luck. Have you tried to install EAP builds from here: https://www.jetbrains.com/resharper/nextversion/#section=windows ?
Does it work better for you?
Thank you!
Until using 2023.1.2, I also got the issues on the relaycommand. Once installing the EAP, I resolved issues until now.
I will keep track it and I'll post if I would get same issue.
I monitored for several days with EAP, the intelligence failed to recogniz compiled variables by mvvm tookit.
It is something different reason, i guess.
Hello Richard,
is it possible to send us a project where we can reproduce the issue?
Thank you!
I have been having this exact issue with 2023.1.2 and VS2022 17.6.2 / 17.6.4
Upgrading to 2023.1.3 seems to have fixed the problem, just in case anyone else finds this thread.
It's broken again with the VS 2024.3
Hello Jdeoworld
Could you please provide a sample solution demonstrating the issue?
You can share it via our upload service.
Thank you.