The Assembly UnityEditor is referenced by Assembly-CSharp

I get this error and I don’t understand why:
ArgumentException: The Assembly UnityEditor is referenced by Assembly-CSharp (‘Library/ScriptAssemblies/Assembly-CSharp.dll’). But the dll is not allowed to be included or could not be found.

I know that it means that the Assembly-CSharp.dll has some code that linking it to Editor dll, but the code that is generating this issue is this one (not an editor script):

		// If we're in the editor, create the game object with hide flags set right away
		GameObject go = UnityEditor.EditorUtility.CreateGameObjectWithHideFlags(name,
			HideFlags.DontSave | HideFlags.NotEditable, typeof(UIDrawCall));
			HideFlags.HideAndDontSave, typeof(UIDrawCall));
		UIDrawCall dc = go.GetComponent<UIDrawCall>();
		GameObject go = new GameObject(name);
		UIDrawCall dc = go.AddComponent<UIDrawCall>();

Considering that the code is handled with #if UNITY_EDITOR, i don’t see the reason why i get that error (i made the basic test #if UNITY_EDITOR1 and the build error disappeared)

This issue happens onUnity 5.5.0f3 , on a project upgraded from Unity 5.3

Any ideas how i can fix this?

@CoSpinu Our company ran into the exact same issue this week and your solution helped. We brainstormed it and a possible solution could be to delete your Library and Temp folders and your .csproj files and let Unity rebuild them. We are under deadline trying to get a large project converted to WebGL and this rebuilding could take hours on our part. If you have a smaller project, it may be worth testing to see if changing your preprocessor directive back to #if UNITY_ENGINE and rebuilding the project works. I’m sure it will save someone a headache.

Best of luck.

I had the same issue and removing the symbols was not an option.
I closed Unity and deleted all of my project and solution files, then did an Xcode replace build and the error went away.

Also make sure that all of your code has properly been migrated. Unity 5.6 deprecated a lot of code and editor scripts don’t always show compile errors in the console.

Got this problem as well, pretty sure all editor stuff guarded correctly with #if UNITY_EDITOR , had anyone report this as a bug to unity? my project size is huge, I found I can’t repro the issue when I create a smaller test project

Having the same issue with Oculus Sample Framework (OVR) for mobile, we get this:

ArgumentException: The Assembly UnityEditor is referenced by Assembly-CSharp (‘Library/ScriptAssemblies/Assembly-CSharp.dll’). But the dll is not allowed to be included or could not be found.
UnityEditor.AssemblyHelper.AddReferencedAssembliesRecurse (System.String assemblyPath, System.Collections.Generic.List1 alreadyFoundAssemblies, System.String[] allAssemblyPaths, System.String[] foldersToSearch, System.Collections.Generic.Dictionary2 cache, BuildTarget target) (at C:/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:142)
UnityEditor.AssemblyHelper.FindAssembliesReferencedBy (System.String paths, System.String foldersToSearch, BuildTarget target) (at C:/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:179)

The file “Assembly-CSharp.dll” is there in the Library, but it is also in the "/TEMP/Staging Area/ " but we removed that and it created it again. We’re dead in the water, we have check this on various versions (5.6.0 & 5.6.1), same issues. The file built prior to importing the OVR content.

Beuller?? Beuller??