Search Unity

Getting warning 'ClassXYZ conflicts with imported type ClassXYZ'

Discussion in 'Scripting' started by tigger, Oct 10, 2019.

  1. tigger

    tigger

    Joined:
    Jan 8, 2013
    Posts:
    95
    I occasionally get the following warning. It's basically saying that a type conflicts with itself.

    Warning code is CS0436.
    Warning Message: The type 'ClassXYZ' in '...path.../ClassXYZ.cs' conflicts with the imported type 'ClassXYZ' in 'Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '...path.../ClassXYZ.cs'.

    There's only one file for the class in the project: ClassXYZ.cs.

    This problem started when I upgraded to 2019.2.6f1.
    Any ideas?
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    Do you have assembly definitions files in your project?
     
  3. tigger

    tigger

    Joined:
    Jan 8, 2013
    Posts:
    95
    Not as far as I know. I didn't create any such thing explicitly / deliberately.

    This just cropped up this morning on a project I've been working on for months. Now I'm seeing the warning with every new class I create. The warning shows up in code that references the "problem" class.
     
  4. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    maybe its some kind of cache conflict ? try closing unity and deleting Library folder, it will be recreated at next run
     
  5. tigger

    tigger

    Joined:
    Jan 8, 2013
    Posts:
    95
    Well, deleting the Libary folder didn't have any effect.

    What did fix the problem was changing the access modifier on the newly created class from public to internal. The warning goes away.

    It appears that all new classes I define going forward will have to be internal, not public, to avoid these warnings.

    (Update: changing the access modifier to internal created its own set of problems. e.g., classes in the "Test" folder, which are part of the CSharp-Testing assembly, couldn't access my internal classes. So, not a good solution!)

    All classes in the project (150+) created before today are marked "public" and they don't have this problem.

    Something somewhere in the bowels of the project changed (some setting?); I have no idea what. It's not related to the source code itself.
     
    Last edited: Oct 11, 2019
  6. tigger

    tigger

    Joined:
    Jan 8, 2013
    Posts:
    95
    Hmmmm....
    So one thing I notice is this:

    In Visual Studio, on the ribbon along the top, below the bar of tabs (open files), what's NORMALLY displayed is className -> methodName.

    Now, however, when I create a new class, the ribbon displays "Assembly-CSharp-Editor -> className -> methodName. Clicking on "Assembly-CSharp-Editor" allows me to switch to "Assembly-CSharp".

    The assembly info isn't there for any other (older) classes. This leads me to believe that these newly created files aren't being associated with the right assembly (?). Is there a way to check the assembly a file is associated with?
     
  7. tigger

    tigger

    Joined:
    Jan 8, 2013
    Posts:
    95
    After wrestling with this for a while, and a few stops and starts of Unity and VS, the problem simply went away.
    Bizarre.
     
  8. SASA2048

    SASA2048

    Joined:
    Aug 8, 2020
    Posts:
    2