Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug VS 22 throws CS8032 after updating to Tech stream 2022.2.0f1

Discussion in 'Code Editors & IDEs' started by shamunity, Dec 11, 2022.

  1. shamunity

    shamunity

    Joined:
    Sep 18, 2015
    Posts:
    22
    Can't shake this off despite hours of googling!

    I'm running:
    • Windows 10 latest build
    • Tech stream 2022.2.0f1.
    • MS VS 22 [17.4.33122] properly linked to Unity for debug
    • Removed all the other unity editor via the hub.
    In unity:
    • Created a new project (all new)
    • Added a blank script (just start and update in there, empty)
    In unity settings:
    • API compatibility level is set to .NET standard 2.1
    • external tool editor is set to MS VS 22 [17.4.33122]

    My machine has the 7.0.100 .NET SDK installed and all the following runtimes:

    Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.NETCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 5.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.WindowsDesktop.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

    In the blank script,
    VS studio is throwing:

    Warning CS8032 An instance of analyzer Unity.MonoScriptGenerator.MonoScriptInfoGenerator cannot be created from C:\Program Files\Unity\Hub\Editor\2022.2.0f1\Editor\Data\Tools\Unity.SourceGenerators\Unity.SourceGenerators.dll: Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.. Assembly-CSharp C:\Program Files\Unity\Hub\Editor\2022.2.0f1\Editor\Data\Tools\Unity.SourceGenerators\Unity.SourceGenerators.dll 1 Active

    I have NO IDEA on how to fix this... anyone has ANY idea what is causing this? I don't want to change my API compatibility level setting as the Unity docs clearly state this has a detrimental effect on the number of targetable build environments...
     
    HaiderBassim04, AriaK and OBiwer like this.
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,304
    Visual Studio can be a little "thenthitive" this way. Here's my crib sheet:

    This may help you with intellisense and possibly other Visual Studio integration problems:

    Sometimes the fix is as simple as doing Assets -> Open C# Project from Unity. Other times it requires more.

    Other times it requires you also nuke the userprefs and .vsconfig and other crufty low-value high-hassle files that Visual Studio tends to slowly damage over time, then try the above trick.

    Barring all that, move on to other ideas:

    https://forum.unity.com/threads/intellisense-not-working-with-visual-studio-fix.836599/

    Also, try update the VSCode package inside of Unity: Window -> Package Manager -> Search for Visual Studio Code Editor -> Press the Update button

    Also, this: https://forum.unity.com/threads/no-suggestions-in-vscode.955197/#post-6227874
     
    Wolfram likes this.
  3. shamunity

    shamunity

    Joined:
    Sep 18, 2015
    Posts:
    22
    Sadly, none of this worked. I tried and tried.
    The questions are:

    • What "defines" which NetStandard version is installed/recognized?
    • How can I change it?
    • What is the consequence of an instance of analyzer Unity.MonoScriptGenerator.MonoScriptInfoGenerator NOT being created?
    • Why does this error seem "rare" (I couldn't find many references, and those that I found were straightforward to understand and fix, this is not).

    Thank you!
     
    HaiderBassim04 likes this.
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,304
    Because Visual Studio is completely optional.

    You could edit 100% of your source files with Notepad if you like.

    Unity compiles your project.

    Visual Studio is not involved in compiling your game.

    Going down your bullet-point questions in order above:

    - irrelevant
    - irrelevant
    - no idea what THAT monstrosity is but I've never used it or heard of it.
     
  5. george_ardeleanu

    george_ardeleanu

    Joined:
    Jul 9, 2021
    Posts:
    2
    Got the exact same warning in VS .NET 2022. It's interesting to note that the latest LTS version (2021.3.16f1) doesn't even have the folder Unity.SourceGenerators where the culprit .dll is located, so it's probably a new addition? The projects created with the LTS version don't display this message. I can confirm this happens in the latest tech stream release also (2022.2.1f1).

    Oh well, it's just a warning, albeit annoying and verbose, things compile and run just fine.
    I invested too much time already in this, Google doesn't help, GPT4 gives IT support level of silly things to try...

    Hopefully Unity will fix it in future releases.
     
    Yuhigh likes this.
  6. Ziflin

    Ziflin

    Joined:
    Mar 12, 2013
    Posts:
    132
    Same warning in VS 2022 after updating from Unity 2022.1 to 2022.2.1f1 today. Also updated Visual Studio Editor 2.0.16 to 2.0.17, so not sure which caused it.
     
  7. nharusame

    nharusame

    Joined:
    Dec 19, 2014
    Posts:
    1
    I found a fix for this problem.
    These Analyzers in the .csproj are generating warnings.

    <Analyzer Include="XXX\UnityEditors\2022.2.0f1\Editor\Data\Tools\Unity.SourceGenerators\Unity.SourceGenerators.dll" />
    <Analyzer Include="XXX\UnityEditors\2022.2.0f1\Editor\Data\Tools\Unity.SourceGenerators\Unity.Properties.SourceGenerator.dll" />

    So, hook the generation of .csproj by AssetPostprocessor and remove these statements, and the warning will not occur.

    Code (CSharp):
    1.     public class CS8032WarningFixer  : AssetPostprocessor
    2.     {
    3.         private static string OnGeneratedCSProject(string path, string content)
    4.         {
    5.             var document = XDocument.Parse(content);
    6.             document.Root.Descendants()
    7.                 .Where(x => x.Name.LocalName == "Analyzer")
    8.                 .Where(x => x.Attribute("Include").Value.Contains("Unity.SourceGenerators"))
    9.                 .Remove();
    10.             return document.Declaration + System.Environment.NewLine + document.Root;
    11.         }
    12.     }
     
  8. Nightmare34

    Nightmare34

    Joined:
    Oct 3, 2020
    Posts:
    7
    I create this script in the editor folder
    add needed using
    Code (CSharp):
    1. using System.Linq;
    2. using System.Xml.Linq;
    3. using UnityEditor;
    Delete .sln file
    Use open C# project in Unity for regenerate .sln file
    And no more warning !
    Thanks a lot :) !
     
    therobby3 likes this.
  9. potter3366

    potter3366

    Joined:
    Oct 15, 2009
    Posts:
    65
    Nightmare34, Can you elaborate a little more clearly please because I trying but without success..

    Unity 2022.2.4f1
    Microsoft Visual Studio (Version 17.2.5)

     
  10. Ziflin

    Ziflin

    Joined:
    Mar 12, 2013
    Posts:
    132
    Unity it's been almost 3 months, any chance of getting this fixed in the editor?

    (Also, thanks @nharusame for the temporary fix!)
     
  11. NielsTerHeijden

    NielsTerHeijden

    Joined:
    Mar 4, 2014
    Posts:
    20
    2022.2.8 Still has these warnings, manually removing the lines from the csproj file doesn't seem to do anything. Every time Unity recompiles the code it will still show all the warnings in the unity console.
     
  12. Ziflin

    Ziflin

    Joined:
    Mar 12, 2013
    Posts:
    132
    @NielsTerHeijden If you have a project for Editor code (or just inside an Editor folder), you can create a new C# file in it and add @nharusame 's code. Then quit Unity and Visual Studio, delete the .sln file in your project's directory, and restart Unity. When you do Assets/Open C# Project hopefully you will no longer get the warning. Though Unity should really fix this on their end as it seems like a simple thing for them to fix.

    Code (CSharp):
    1.  
    2.     using System.Linq;
    3.     using System.Xml.Linq;
    4.     using UnityEditor;
    5.  
    6.     public class CS8032WarningFixer  : AssetPostprocessor
    7.     {
    8.         private static string OnGeneratedCSProject(string path, string content)
    9.         {
    10.             var document = XDocument.Parse(content);
    11.             document.Root.Descendants()
    12.                 .Where(x => x.Name.LocalName == "Analyzer")
    13.                 .Where(x => x.Attribute("Include").Value.Contains("Unity.SourceGenerators"))
    14.                 .Remove();
    15.             return document.Declaration + System.Environment.NewLine + document.Root;
    16.         }
    17.     }
     
    therobby3 likes this.
  13. NielsTerHeijden

    NielsTerHeijden

    Joined:
    Mar 4, 2014
    Posts:
    20
    @Ziflin I've included the code to automatically remove those lines from the csproj file but sadly the warnings are still there when unity recompiles the code after a change. On startup there aren't any problems.

    This might be expected because unity doesn't use the csproj files for it's compilation of the code. It uses some other mechanism and I think we injected our analysers into that mechanism as well. I think it's via the csc.rsp file next to the .asmdef file but I need to test out more. Maybe something can be done using the .ruleset.
     
  14. vallis_unity

    vallis_unity

    Joined:
    Apr 14, 2022
    Posts:
    73
    Same issue with Unity 2023.1.0b5 and VS 2022 17.5.1.

    Even if removing the analysers from the project worked it's not a great long term solution.
     
  15. NielsTerHeijden

    NielsTerHeijden

    Joined:
    Mar 4, 2014
    Posts:
    20
    You can disable analyzer rules pretty targeted

    Code (CSharp):
    1. [assembly: SuppressMessage("StyleCop.Analyzer", "SA1025", Scope = "namespaceanddescendants", Target = "~N:UnityEngine")]
    Would disable that rule for only the UnityEngine namespace. Sadly I don't know the namespace of "Unity.SourceGenerators\Unity.MonoScriptGenerator.MonoScriptInfoGenerator\AssemblyMonoScriptTypes.gen.cs" or the precise class or module or anything that would let me target the SuppressMessage :(

    I can't find the file on my system.


    -- edit --

    Found the class name. Add the following lines in a file next to you .asmdef file. and it will suppress all the warnings.

    Code (CSharp):
    1. // <auto-generated />
    2. /*
    3. * Suppresses Unity2022.2 warning messages about SourceGenerated code
    4. */
    5. using System.Diagnostics.CodeAnalysis;
    6.  
    7. [assembly: SuppressMessage("StyleCop.Analyzer", "SA1013", Justification = "AutoGenerated Code", Scope = "Type", Target = "UnitySourceGeneratedAssemblyMonoScriptTypes")]
    8. [assembly: SuppressMessage("StyleCop.Analyzer", "SA1012", Justification = "AutoGenerated Code", Scope = "Type", Target = "UnitySourceGeneratedAssemblyMonoScriptTypes")]
    9. [assembly: SuppressMessage("StyleCop.Analyzer", "SA1025", Justification = "AutoGenerated Code", Scope = "Type", Target = "UnitySourceGeneratedAssemblyMonoScriptTypes")]
    10. [assembly: SuppressMessage("StyleCop.Analyzer", "SA1001", Justification = "AutoGenerated Code", Scope = "Type", Target = "UnitySourceGeneratedAssemblyMonoScriptTypes")]
    11. [assembly: SuppressMessage("StyleCop.Analyzer", "SA1517", Justification = "AutoGenerated Code", Scope = "Type", Target = "UnitySourceGeneratedAssemblyMonoScriptTypes")]
    12. [assembly: SuppressMessage("StyleCop.Analyzer", "SA1003", Justification = "AutoGenerated Code", Scope = "Type", Target = "UnitySourceGeneratedAssemblyMonoScriptTypes")]
    13. [assembly: SuppressMessage("StyleCop.Analyzer", "SA1600", Justification = "AutoGenerated Code", Scope = "Type", Target = "UnitySourceGeneratedAssemblyMonoScriptTypes")]
    14. [assembly: SuppressMessage("StyleCop.Analyzer", "SA1404", Justification = "AutoGenerated Code", Scope = "Type", Target = "UnitySourceGeneratedAssemblyMonoScriptTypes")]
    15. [assembly: SuppressMessage("StyleCop.Analyzer", "SA1307", Justification = "AutoGenerated Code", Scope = "Type", Target = "UnitySourceGeneratedAssemblyMonoScriptTypes")]
    16. [assembly: SuppressMessage("StyleCop.Analyzer", "SA1516", Justification = "AutoGenerated Code", Scope = "Type", Target = "UnitySourceGeneratedAssemblyMonoScriptTypes")]
    17. [assembly: SuppressMessage("StyleCop.Analyzer", "SA1201", Justification = "AutoGenerated Code", Scope = "Type", Target = "UnitySourceGeneratedAssemblyMonoScriptTypes")]
    18. [assembly: SuppressMessage("StyleCop.Analyzer", "SA1502", Justification = "AutoGenerated Code", Scope = "Type", Target = "UnitySourceGeneratedAssemblyMonoScriptTypes")]
    19. [assembly: SuppressMessage("StyleCop.Analyzer", "SA1500", Justification = "AutoGenerated Code", Scope = "Type", Target = "UnitySourceGeneratedAssemblyMonoScriptTypes")]
    20. [assembly: SuppressMessage("StyleCop.Analyzer", "SA1633", Justification = "AutoGenerated Code", Scope = "Type", Target = "UnitySourceGeneratedAssemblyMonoScriptTypes")]
    21. [assembly: SuppressMessage("StyleCop.Analyzer", "SA1649", Justification = "AutoGenerated Code", Scope = "Type", Target = "UnitySourceGeneratedAssemblyMonoScriptTypes")]
     
    Last edited: Mar 3, 2023
  16. Nightmare34

    Nightmare34

    Joined:
    Oct 3, 2020
    Posts:
    7
    1) Create a script In Editor folder with this content

    Code (CSharp):
    1. using System.Linq;
    2. using System.Xml.Linq;
    3. using UnityEditor;
    4. public class CS8032WarningFixer : AssetPostprocessor
    5. {
    6.     private static string OnGeneratedCSProject(string path, string content)
    7.     {
    8.         var document = XDocument.Parse(content);
    9.         document.Root.Descendants()
    10.             .Where(x => x.Name.LocalName == "Analyzer")
    11.             .Where(x => x.Attribute("Include").Value.Contains("Unity.SourceGenerators"))
    12.             .Remove();
    13.         return document.Declaration + System.Environment.NewLine + document.Root;
    14.     }
    15. }
    2) Delete .sln file in your project
    3) Go to Assets/Open C# Project
     
    Tivan, CharlieCook, AriaK and 3 others like this.
  17. therobby3

    therobby3

    Joined:
    Jan 30, 2019
    Posts:
    131
    Has anyone filed a bug report for this? I've been getting this issue after updating from 2021 to 2022, and would like to get it out of my warnings. I'm using 2022.2.12 and it is still showing up. If anyone has filed a bug report, please post so I can upvote it.
     
  18. blu3drag0n

    blu3drag0n

    Joined:
    Nov 9, 2018
    Posts:
    94

    Thanks, clean description of what to do, worked like a charm :)
     
  19. Wolfram

    Wolfram

    Joined:
    Feb 16, 2010
    Posts:
    253
    Thanks!
     
    Nightmare34 likes this.
  20. SunriseEUW

    SunriseEUW

    Joined:
    Oct 30, 2022
    Posts:
    3

    Where do i have to put this script? i tried it too but i think i made something wrong. Im still getting that warning. But my programs work actually. Im kinda scared that i will have later on my project issues.
     
  21. Wolfram

    Wolfram

    Joined:
    Feb 16, 2010
    Posts:
    253
    Put it in any asset folder named "Editor" (or create one).
     
  22. megaalex112

    megaalex112

    Joined:
    Jun 20, 2021
    Posts:
    1
    Create a folder named "Editor" inside the Assets folder of your project and put the script there
     
  23. SunriseEUW

    SunriseEUW

    Joined:
    Oct 30, 2022
    Posts:
    3
    Thanks now it works perfectly !
     
  24. Olnipa

    Olnipa

    Joined:
    Oct 27, 2022
    Posts:
    3
    Oh, thank you so much! It's work for me. Unity 2022.3.4f1.0.14531
     
  25. PepperATM

    PepperATM

    Joined:
    Sep 28, 2020
    Posts:
    6
    Nope. Didn't work for me.
     
  26. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    596
    It's been so long since I applied a workaround fix (CS8032WarningFixer) for this problem so I don't remember the details but now I tried deleting CS8032WarningFixer script in my Unity 2023.2.2 project and I think I'm not experiencing the problem anymore. Can anyone confirm this please (if you are using 2023.2.x version)?