-
Notifications
You must be signed in to change notification settings - Fork 463
[Bug] VS2019 Syntax/Code Highlighting for Custom Types (since v1.3.2) #1815
Comments
Youi are right, I though I had broken some configuration when syntax highlighting worked differently between two of my projects. Downgrading XCT to 1.3.1 helped. Thank you! |
@Countryen does it only show this behaviour after installing the package? If you close visual studio and reopen does it behave? @pictos is there anyway the source generator could be upsetting VS? I know it struggles with new files being added like this sometimes |
On the repro project used that shouldn't work (?) because Xamarin doesn't support net5, if you target netstandard do you get the same behavior?
Maybe... Could be some bug on VS tooling, I would say if that's the case this is more a VS or SourceGenerator bug than XCT bug. @Countryen or @danielkraut could you attach a small repro? |
@bijington @pictos Thanks for the replies. I want to add, that I don't think that not using the latest version should be promoted but currently that's just what is working (for both of us, it seems).
Yes, but this is the only package that is affected and I can check but think some of our other packages already use SourceGenerators, too. I thought it's best to start here, but if you point me to the right place / forward this, I will be very grateful.
Yes. As seen in the picture above. I just go to my csproj-file and have the PackageReference commented out (so the package is not installed). At this time, the colours are correct.
When I close VS and reopen - this is what happens (sometimes):
So it is kinda like blinking/flashing first. After the scrolling, the colours don't return until I reopen VS. It's the same every time and on multiple of our machines (all Windows 10). To clarify, the problem occurs for my team in our library project which targets "netstandard2.0" (and is a dependency of our Xamarin.Forms 5.0 project using UWP/Android/etc.). Just for simplicity, I created a new console project to find the issue. I will attach a repo on |
Attached please find the reproducing sample.
Do the same with version 1.3.2 and 1.3.1 - with v1.3.1 it works correctly. |
@Countryen as @pictos suggested this is expected to not work in a Console app. In fact I am surprised you are even allowed to add the package. Although I have tested and can confirm that VS/NuGet don't stop you. Admittedly it does report some issues though. Following the behaviour you have mentioned in a clean Xamarin Forms application works fine here for me. I did hit some issues initially though... I had to update Xamarin.Forms (5.0.0.2337) to the latest before I could install the Xamarin.CommunityToolkit package. Can you confirm if you are referencing the latest version of Xamarin.Forms or at least 5.0.0.2291? Also did you use the NuGet Package Manager inside Visual Studio to make the change to your projects or are you simply editing the project files directly? |
I also encountered this issue with an existing project (just posted something in the discussion section on this very topic). I already had the latest Xamarin.Forms (5.0.0.2337) when I installed the latest Xamarin.Community.Toolkit package (V2.0.0) when I noticed this issue as well. The project I have was building an app for Android as a target. I'm running Visual Studio 2019 Professional (V16.11.10). Perhaps it's a weird interaction with first installing Xamarin.Forms 5.0.0.2337 and then installing >= V1.3.2 of XCT? EDIT: I did have the preview version for VS that allowed MAUI, including the preview of Visual Studio 2022, but wound up uninstalling everything except VS 2019. |
@bijington I understand that it should not work in a console app project, that was just a simple example. The behavior is the same when I add a new Xamarin.Forms project (blank app, only Android and UWP).
I also have to highlight that I have the latest MAUI Preview installed (VS 22 Preview with .NET 6 Preview) and not removed it, yet. But @PrezSkroob has removed it. All of our team members have had one version of MAUI Preview installed once. Maybe important to add: It only happens in the project that has the package reference. Even though the "UWP" project uses the "Shared" project as reference (includes it) and I can access the XCT stuff in the UWP project, here it works. It's only happening in the netstandard2.0 project for me. (Note: I've created a separate CustomEnum in the UWP project for this). |
I've now also tried using a different packages online, and I can't reproduce the error with other projects. |
When I checkout the tag 2.0.0 of this project and compile that on my machine, then use the compiled (Debug/Release) DLL file as reference instead of the NuGet Package everything is fine, it's only when I use the NuGet package. Maybe it's related to installing MAUI and some weird conflict between the different Visual Studio versions, I will try with a machine that has not installed any MAUI preview so far. |
It seems that it might be related to installing this toolkit package through the NuGet Package manager and having the preview version of MAUI installed, as that was my setup. I'm in the process of getting a new SSD installed on my machine, and once I get Visual Studio re-installed, I will check the project I'm working with to see if the issue is still present. |
The project I'm working on also uses netstandard2.0, if that helps with duplicating/tracking this. |
New SSD installed. Installed fresh installation of Visual Studio (first was Visual Studio 2022 due to having issues finding the 2019 installer, but that was eventually found and installed). Same issue occurs. Uninstalled Visual Studio 2022 and issue remains. Really wish Visual Studio 2019 was found earlier because that may have helped more for finding the root cause of this issue. |
Do we know if the binary image of the tagged V2.0.0 matches the binary image available through the NuGet package? I've encountered issues where changes were inadvertently made between tagged and released binaries (for other non-Visual Studio projects). |
I've also managed to install the repro on a device without VS 2022 ever installed - same issue. But, I first tried with my old version of VS 2019 (16.10.4) which worked! So it could be a mix between XCT package and VS2021 new versions. I am not sure how to install/downgrade older versions of VS to test which version works and this was my private PC that I do not often use for development, so I will need to test further. If you like @PrezSkroob, could you try downgrading or installing a previous version of VS to see for yourself? |
Very interesting. I will have to download an older version of Visual Studio and give it a try. If I can figure out how. During my reinstall, I was able to get the latest version (available here however, I haven't been successful in trying an older version. I will look around and see if I can figure out how, and I'll post instructions here. EDIT: Apparently, there are instructions here, and it also includes links to previous versions!
|
I haven't gotten around to trying to downgrade my version of Visual Studio, I did notice something interesting when using the pre-processor. (I'm using Visual Studio 2019 V16.11.11 now by the way) In one of my source files, if I declare something like:
Then the syntax/code highlighting works again for all code that is in the #if declaration. So somehow the pre-processor is able to correct whatever bug is causing it? |
Description
Since upgrading our NuGet packages over the years all our team member have the same issue: Sometimes our Visual Studio Code/Syntax highlighting isn't working. I've finally managed to reproduce this and track down what causes this: The NuGet package Xamarin.CommunityToolkit.
If I create a completely new (console) application everything works fine. I add a custom type and see that type highlighted (green for me) when I instantiate a variable/property with that type. See the image, in this case a custom enum (which is defined in CustomEnum.cs next to Program.cs).

But, as seen in the next image, as soon as I add NuGet package Xamarin.CommunityToolkit, the "CustomEnum" isn't green anymore.

If I remove the NuGet package, it works again.
Please note that "sometimes" it works for a short time. Then, all custom types have colour. But this colour is gone after "some" time, especially when scrolling.
This is just an example. We noticed this behaviour in our real Xamarin.Forms 5.0 application with Xamarin.CommunityToolkit and many other NuGet packages used. But, this is only the case for Xamarin.CommunityToolkit (if I remove all other packages, it still is not green and if I only remove Xamarin.CommunityToolkit it works).
I can not reproduce this in VS2022 but we need to be able to use VS2019.
I've tested different versions:
Systems used:
Steps to Reproduce
Expected Behavior
The code/syntax highlighting must be correct for the type of the added property in Pogram.cs.
It should be "green" (for dark mode, depending on colour settings).
Actual Behavior
The code/syntax highlighting isn't correct for the type of the added property in Program.cs.
It's white/default coloured (for dark mode, depending on colour settings).
Basic Information
Workaround
Only use Xamarin.CommunityToolkit
<= v1.3.1
or use Visual Studio 2022.The text was updated successfully, but these errors were encountered: