Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Assembly-CSharp-Editor.csproj could not be loaded - Because it doesn't exist

Discussion in 'Editor & General Support' started by Tommo120, May 3, 2018.

  1. Tommo120

    Tommo120

    Joined:
    Mar 3, 2015
    Posts:
    6
    Hi everyone!

    So I was very excited to see Unity 2018 get it's first official release, I had tried the beta a month or so back and had this exact same problem I'm having right now with the non-beta version. I looked around and couldn't find anyone else having the same issue, chalked it up to it being a beta version issue, and went back to the previous 2017 release to continue my work.

    The problem occurs when I try to open any of my scripts in Visual Studio 2017 (v15.6.6). Visual Studio tries to open two C# project files alongside the usual project and solution files, however, they don't exist. The two files are Assembly-CSharp-Editor.csproj and Assembly-CSharp-Editor-firstpass.csproj. Because these two files don't exist, and VS really wants them to, I don't get ANY intellisense, and all of my scripts are considered miscellaneous files.

    If anyone has any ideas at all how to fix this, I would really appreciate the help!

    EDIT:

    I just noticed I have an error in Unity that I've never seen before

    XmlException: a name did not start with a legal character 32 ( ) Line 84, position 24.
    Mono.Xml2.XmlTextReader.ReadName (System.String& prefix, System.String& localName)
    Mono.Xml2.XmlTextReader.ReadName ()
    Mono.Xml2.XmlTextReader.ReadEntityReference (Boolean ignoreEntityReferences)
    Mono.Xml2.XmlTextReader.ReadReference (Boolean ignoreEntityReferences)
    Mono.Xml2.XmlTextReader.ReadText (Boolean notWhitespace)
    Mono.Xml2.XmlTextReader.ReadContent ()
    Mono.Xml2.XmlTextReader.Read ()
    System.Xml.XmlTextReader.Read ()
    Mono.Xml.XmlFilterReader.Read ()
    System.Xml.Linq.XElement.LoadCore (System.Xml.XmlReader r, LoadOptions options)
    System.Xml.Linq.XNode.ReadFrom (System.Xml.XmlReader r, LoadOptions options)
    System.Xml.Linq.XContainer.ReadContentFrom (System.Xml.XmlReader reader, LoadOptions options)
    System.Xml.Linq.XElement.LoadCore (System.Xml.XmlReader r, LoadOptions options)
    System.Xml.Linq.XNode.ReadFrom (System.Xml.XmlReader r, LoadOptions options)
    System.Xml.Linq.XContainer.ReadContentFrom (System.Xml.XmlReader reader, LoadOptions options)
    System.Xml.Linq.XElement.LoadCore (System.Xml.XmlReader r, LoadOptions options)
    System.Xml.Linq.XNode.ReadFrom (System.Xml.XmlReader r, LoadOptions options)
    System.Xml.Linq.XContainer.ReadContentFrom (System.Xml.XmlReader reader, LoadOptions options)
    System.Xml.Linq.XElement.LoadCore (System.Xml.XmlReader r, LoadOptions options)
    System.Xml.Linq.XNode.ReadFrom (System.Xml.XmlReader r, LoadOptions options)
    System.Xml.Linq.XContainer.ReadContentFrom (System.Xml.XmlReader reader, LoadOptions options)
    System.Xml.Linq.XDocument.ReadContent (System.Xml.XmlReader reader, LoadOptions options)
    System.Xml.Linq.XDocument.LoadCore (System.Xml.XmlReader reader, LoadOptions options)
    System.Xml.Linq.XDocument.Load (System.IO.TextReader reader, LoadOptions options)
    System.Xml.Linq.XDocument.Parse (System.String s, LoadOptions options)
    System.Xml.Linq.XDocument.Parse (System.String s)
    SyntaxTree.VisualStudio.Unity.Bridge.ProjectFilePostprocessor.OnGeneratedCSProject (System.String path, System.String content)
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
    Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
    System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
    UnityEditor.AssetPostprocessingInternal.CallOnGeneratedCSProject (System.String path, System.String content) (at C:/buildslave/unity/build/Editor/Mono/AssetPostprocessor.cs:75)
    UnityEditor.VisualStudioIntegration.SolutionSynchronizer.SyncProjectFileIfNotChanged (System.String path, System.String newContents) (at C:/buildslave/unity/build/Editor/Mono/VisualStudioIntegration/SolutionSynchronizer.cs:310)
    UnityEditor.VisualStudioIntegration.SolutionSynchronizer.SyncProject (MonoIsland island, System.Collections.Generic.Dictionary`2 allAssetsProjectParts, UnityEditor.Scripting.Compilers.ResponseFileData responseFileData, System.Collections.Generic.List`1 allProjectIslands) (at C:/buildslave/unity/build/Editor/Mono/VisualStudioIntegration/SolutionSynchronizer.cs:303)
    UnityEditor.VisualStudioIntegration.SolutionSynchronizer.GenerateAndWriteSolutionAndProjects (ScriptEditor scriptEditor) (at C:/buildslave/unity/build/Editor/Mono/VisualStudioIntegration/SolutionSynchronizer.cs:234)
    UnityEditor.VisualStudioIntegration.SolutionSynchronizer.Sync () (at C:/buildslave/unity/build/Editor/Mono/VisualStudioIntegration/SolutionSynchronizer.cs:206)
    UnityEditor.SyncVS.SyncIfFirstFileOpenSinceDomainLoad () (at C:/buildslave/unity/build/Editor/Mono/SyncProject.cs:199)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
     
    Last edited: May 3, 2018
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Make sure you choose Visual Studio 2015 or 2017 in External Tools.
     
  3. Tommo120

    Tommo120

    Joined:
    Mar 3, 2015
    Posts:
    6
    It's already set to, pretty sure it defaults to using Visual Studio if it's installed.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Which one is it set to, 2015 or 2017? You have a choice in 2018.1
     
  5. Tommo120

    Tommo120

    Joined:
    Mar 3, 2015
    Posts:
    6
    2017, it's the only version I have installed.
     
  6. couetcouet88

    couetcouet88

    Joined:
    Jun 10, 2014
    Posts:
    5
  7. Tommo120

    Tommo120

    Joined:
    Mar 3, 2015
    Posts:
    6
    Unfortunately I haven't found a solution. I'm honestly losing hope at this point and think the only thing that's going to work is reinstalling windows, not something I want to do just for the latest version of Unity, especially since the previous version works without problems.
     
  8. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    372
    I'm getting this error too -- like it can't properly create the default C# assembly. So I created an Assembly Definition asset and it worked! I guess the assembly just has to be called something else besides the default name of Assembly-CSharp?
     
    XriMzZ likes this.
  9. Tommo120

    Tommo120

    Joined:
    Mar 3, 2015
    Posts:
    6
    Oh my god, that worked. Thank you so much :)
     
    ModLunar likes this.
  10. Richie_V

    Richie_V

    Joined:
    Dec 3, 2014
    Posts:
    5
    Had exactly the same problem, after trying VS 2015 saw it actually generated the Assembly-CSharp and Assembly-CSharp-Editor but failed to load them because I had a folder with an & in it's name, tried VS 2017 after changing the folder name and everything worked ok after that
     
    Matt-P-Hoare-Lea and ow3n like this.
  11. Scape-It

    Scape-It

    Joined:
    Sep 29, 2018
    Posts:
    2
    Wow! Creating a new Assembly Definition asset worked! Thanks a lot for all your input!
     
  12. ow3n

    ow3n

    Joined:
    May 8, 2016
    Posts:
    14
    I also had an ampersand ("&") in my path. Removing it and restarting everything fixed it!
     
  13. MasterKaygee

    MasterKaygee

    Joined:
    Oct 30, 2018
    Posts:
    2
    thanks guy,

    I had exactly the same issue.

    it works without the & in my folder name
     
  14. nitinkipa098

    nitinkipa098

    Joined:
    Jan 21, 2019
    Posts:
    2
    And how do I create Assembly Definition Asset? Please give beginner friendly answer. :)
     
  15. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    @nitinkipa098 Rightclick -> Create Assembly Defintion in a folder containing scripts. Anything below it will be thrown into an assembly with the same name. For asmdef's: They are not required until you have a single package or plugin using them (and in most cases if they are structured correctly you can simply delete the asmdef).

    Create an asmdef in any /Editor folder. E.g. /Plugins/SomePlugin/Editor could have 2 asmdefs. One in /SomePlugin and one in /SomePlugin/Editor where the one in /SomePlugin/Editor creates a reference to /SomePlugin/SomePlugin.asmdef (if the code in /Editor requires any code from SomePlugin). However you could also have 1 asmdef in /Plugins and simply reference that from your /Editor asmdef. Then all code which is not below your /Editor asmdef file will be thrown into the /Plugins/Plugins.asmdef because the first found asmdef going upward in the hierarchy is used.

    However, for the error in the initial post: Usually deleting the csproj and sln files and letting unity recreate them solves this error. In many cases you had a script in an /Editor folder before, but do not have now anymore. The sln is not updated correctly and the -Editor.dll fails to create. One reason you possibly do not have a script there anymore is because you now added a .asmdef file ANYWHERE in your project (e.g. adding a package or plugin from the asset store using them).
     
  16. XriMzZ

    XriMzZ

    Joined:
    Feb 17, 2019
    Posts:
    1
    I'm using Unity 2020 and Vs2019 and I encounter the same issue and creating a new Assembly Defintion helped! . Thank you for the explanation
     
  17. phixell

    phixell

    Joined:
    Jun 10, 2010
    Posts:
    11
    Can you detail how to create an Assembly Definition asset?
     
  18. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    372
    Sure thing!
    When you're inside your Unity project, you can right click in any Project View, and go to Create > Assembly Definition.
    upload_2021-10-25_10-40-43.png

    By convention, I usually put it under Assets/Scripts/[Assembly Name]/[Assembly Name].asmdef.
    Any C# files you create alongside it in the same folder or in any subfolders will now get automatically get compiled into an assembly of the name you choose.

    It has some other settings, like if your assembly needs to reference other assemblies or DLLs,
    Or if the assembly of code should only exist in the Unity editor, builds, certain platforms, etc.

    I always create AssemblyDefinitions now in every project I create, so that I have full control over what references I need, what platform(s) they'll be included in, (for example, I no longer use the magic "Editor" folder anymore. I just create an assembly that is only included in the Unity editor and nowhere else), etc.

    ---

    If you need an editor assembly to reference internal members of another assembly you wrote, look into "Friend Assemblies" and System.Runtime.CompilerServices and [InternalsVisibleTo(string)].

    I use that all the time so I can make editor GUI (buttons, inspectors, etc.) that call into internal methods/properties.
    I still do try to keep my instance fields private, with internal getters only if necessary.
    Internal fields could spell messy code.. haha.

    ---

    I hope this helps!
     
    Perturbator858 likes this.
  19. phixell

    phixell

    Joined:
    Jun 10, 2010
    Posts:
    11
    Thank you very much for the detailed reply. It is very helpful. Cheers.
     
    ModLunar likes this.
  20. Perturbator858

    Perturbator858

    Joined:
    Jan 21, 2021
    Posts:
    7
    Creating Assembly Definition solved my problem. Thank you so much
     
    KarlKarl2000 and ModLunar like this.