Warning: Type conflicts with the imported type

I can’t wrap my head around this warning, and I’m not sure if it’s actually important but I’m trying to find out. I’ve scoured the forums and couldn’t find a solution that works in my case, though it’s likely that’s due to my lack of understanding of the issue. From what I understand, the error is usually caused when referencing the containing class when declaring a variable, but this class doesn’t reference itself.

Capitalization/renaming was mentioned a bunch but if I rename the struct I need to rename the list, etc, so that doesn’t work as a solution.


Any help pointing me towards a solution would be seriously appreciated, everything in the project works fine but having warnings is never a nice thing, especially without understanding them.
Here’s the warning and the class throwing the errors:


‘The type ‘DevShortcutItem’ in ‘/Users/Orion/Game Development/Parabola/Assets/Parabola/Code/Developer/DevShortcutDisplay.cs’ conflicts with the imported type ‘DevShortcutItem’ in ‘Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’. Using the type defined in ‘/Users/Orion/Game Development/Parabola/Assets/Parabola/Code/Developer/DevShortcutDisplay.cs’. [Assembly-CSharp-Editor]’


public class DevShortcutDisplay : MonoBehaviour
{

// Some Other Variables

    public List<DevShortcutItem> Shortcuts = new List<DevShortcutItem>();

    Rect windowRect = new Rect(80, 55, 250, 240);
    List<string> shortcutString;

    void Start()
    {
        shortcutString = new List<string>();
        foreach (DevShortcutItem item in Shortcuts)
        {
            shortcutString.Add(Reveal + " + '" + item.Key + "' to " + item.Description);
        }
    }

    void OnGUI()
    {
        GUI.backgroundColor = Color.black;

        if (!HiddenByDefault || Input.GetKey(Reveal))
        {
            GUI.skin.font = DefaultFont;
            windowRect = GUILayout.Window(0, windowRect, CreateWindow, "Shortcuts");
        }
    }

    void CreateWindow(int windowID)
    {
        for (int i = 0; i < Shortcuts.Count; i++)
        {
            if (Input.GetKey(Shortcuts*.Key))*

{
GUI.skin.font = HighlightFont;
GUILayout.Label(shortcutString*);*

Shortcuts*.Event.Invoke();*
}
else
{
GUI.skin.font = DefaultFont;
GUILayout.Label(shortcutString*);*
}
}

}
}

[Serializable]
public struct DevShortcutItem
{

public KeyCode Key;
public string Description;
public UnityEvent Event;
}

I got this error for a class that I was modifying and was referencing in other scripts. What I did was restart Unity and the error went away. I wonder if it had something to do with one assembly (editor perhaps?) compiling and the other was not.

You have two definitions of the same Type (class), even though they are on different Assemblies (Assembly-CSharp(runtime) and Assembly-CSharp-Editor(editor time)) they are both “wrapped” in the default(root) namespace (for each Assembly) meaning they don’t need specific instructions to be accessed (counter ex using UnityEngine.UI to access UI elements).

Now on editor time Unity loads automatically both (while it loads only first one on runtime) thus it stumbles on two definitions, to resolve it, it chooses to use the one of Assembly-CSharp-Editor because it knows that you work on edit time.

Anyway to fix it you need to define which one you want it to use. The easiest way to do so would be to change the name of one of the two classes, or wrap one and or both on different namespaces.

Of course you can ignore it if you don’t want to use the definitions from Runtime on edit time (bad practice).

Cheers.

I guess you created a build of your game inside your assets folder. Never do this. If you want to create a build it should be outside the Assets folder of your project.

Sometimes I get this error - it’s a bug though in my case… All I have to do to fix it is change the first letter of my script file name from upper case to lowercase in the Project window…
and then change the name / class accordingly in my script. Idk why this happens… just does - and Idk why this fix works … but in my case it always does. - Otherwise you probably have 2 copies of the same script / same class name for 2 diff scripts. Hope this helps.

Just got this error myself, its just because visual studio stayed open with scripts in it while i upgraded unity version. Close visual studio, restart unity, no more error.

For me, I pulled a C# project from GitHub into my unity project. In the “bin” folder of the C# project there was an assembly (build) of the project - which is a .dll file of the same name of the classes with the conflicting names. Since I would rather have access to the code (so I can edit and make changes as desired) I deleted the .dll files that were causing the conflict. In fact, I deleted the entire “bin” folder altogether and everything was fixed.

Specifically my issue was with using DryWetMidi libraries, but this could help for anyone with similar situation.