Visual Studio suddenly populated with red error lines despite code working prior in unity 2022.3.43f1

TLDR: Visual Studio Portrays valid code/warnings as errors despite working in the Unity editor, and not being marked so prior.

For the past two months I’ve been working on creating a turn-based RPG, Up until this point I had been using Visual Studio 2019. Occasionally Visual Studio would not recognize Unity namespaces and I would have to redownload the Visual Studio editor for Unity. This worked up until recently while I was trying to solve an issue with an index value outside of range.

Suddenly all of my scripts in Visual Studio show errors for coroutines, switching between enums missing brackets for one line if statements, functions as “unused values” that are used, and various expressions that “could be simplified”. Some functions that Visual Studio even recommended that I simplify prior are now being marked as errors.




To try and solve this issue I have tried a number of solutions I found on forums:
a.) Reinstall Visual Studio Editor for Unity.
b.) Update Visual Studio Editor for Unity.
c.) Reimport all assets.
d.) Delete Visual Studio cache.
e.) Delete the sln file, .csproj files, and hidden .vs file.
f.) Check that the external script editor is connected and regenerated project files.
g.) Delete Visual Studio 2019 and all references to it on my computer and upgrade to Visual Studio 2022.
h.) Create a new project and a new script file within that project to see if my initial project is corrupted. The same issues occurred.

I believe that perhaps Visual Studio is showing some warnings as errors, however, This does not explain the contradictory recommendations. i.e. recommending I simplify a function, and then hours later show this as an error and recommend the original code.


Unity still runs, and none of the marked errors except for the original index error that I have been trying to fix show up on the console.

I am at a loss for what to do and I can’t get rid of these red lines, I have even turned my Laptop off and on again. Nothing is working, and although these red lines do not hinder Unity’s ability to execute functions, They hinder my ability to identify actual errors within the code.

I am not particularly an expert in Visual Studio nor Unity, Yet I have tried all of the solutions I could find that I could do with my MacBook and version of Unity.

(Edit: im unsure why this was tagged as 6-0 preview, I set the version to 2022.3LTS)