Search Unity

Bug The type or namespace 'TMPro' could not be found - Visual Studio Community 2019 error

Discussion in 'UGUI & TextMesh Pro' started by ROBYER1, Jun 9, 2020.

  1. ROBYER1

    ROBYER1

    Joined:
    Oct 9, 2015
    Posts:
    1,454
    So I have been using TextMesh Pro for well over a year in my project, today seemingly out of nowhere, Visual Studio Community 2019 said it couldn't find the namespace for 'TMPro' when adding 'using TMPro' to my scripts.

    I was dumbfounded as to why as the scripts work fine in the editor! I have reported this at (Case 1254352)

    I did later find the fix but this is unexpected behaviour as the fix involved scripts from the optional Examples and Extras pack. The core TMPro package shouldn't have namespace issues like this.

    Edit: even with this fix in use, the use of 'TextMeshProUGUI' as a variable produces namespace missing errors also!

    The fix: I went to the TextMesh Pro option window in the editor (Window->TeshMesh Pro), and imported the "TMP Examples and Extras." I had already imported the Essentials, but apparently, there's something missing from essentials that stops Visual Studio from recognizing the namespace.
     
    Last edited: Jun 9, 2020
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    This sounds like a Visual Studio and Visual Studio project solution generation issue.

    Other than importing the TMP Essential Resources, there is nothing needed from the TMP Examples & Extras unless you are using some of the resources or scripts contained in them.

    There have been a few similar posts about this in the past where sometimes the issue occurs with VSCode, Visual Studio, Rider, Etc.

    In most cases, deleting the project solution files at the root of the project as well as the Library folder resolves these issues. Keep in mind that for very large project deleting the library folder is a pain but for many projects the re-import process is pretty quick.
     
    ROBYER1 likes this.
  3. ROBYER1

    ROBYER1

    Joined:
    Oct 9, 2015
    Posts:
    1,454
    @Stephan_B thanks for this answer, I will have to force myself through the library regeneration soon in that case. Hopefully this forum post is a clear lead to people seeing the solution.

    I initially regenerated the project solution, deleted the solution files and tried making them fresh but it is likely it's the library folder itself causing this issue.
     
  4. darkLink_32

    darkLink_32

    Joined:
    Apr 22, 2018
    Posts:
    5
    Hello, I am having this same issue, though deleting the solution files and library folder did not fix it. Has there been another solution found for this issue since it was reported?

    Thank you,
     
  5. darkLink_32

    darkLink_32

    Joined:
    Apr 22, 2018
    Posts:
    5
    Found the solution:

    It seems that if you have an assembly definition file (.asmdef file) as a part of your project, you need to add a reference to the Unity.TextMeshPro.dll to it through the inspector, or at least I did. Once I did this, I was able to reference the TMPro namespace without error. Unity.TextMeshPro.dll can be found in the Library\ScriptAssemblies directory of the project.

    Really the "TMP Essential Resources" and "TMP Examples & Extras" do not affect being able to reference the TMPro namespace, because the assembly is installed by default (at least in newer unity versions). I was able to have "using TMPro" without importing "TMP Essential Resources" and "TMP Examples & Extras"; I just needed to add the reference to my .asmdef file. I mean "TMP Essential Resources" is needed for doing other stuff, but it does not affect referencing the package.

    The post here helped me find this out:

    https://stackoverflow.com/a/69380029/16248653
     
    Last edited: Feb 7, 2023
    HeOuaisMec, Bermrad and ur0pb like this.
  6. ADNOC_LNG

    ADNOC_LNG

    Joined:
    Mar 7, 2021
    Posts:
    4
    Search in your unity project for the project's (Assembly definition Asset). Open it.
    Go to Assembly Definition References > + > add "Unity.TextMeshPro".
    That sould solve the problem.
     

    Attached Files:

  7. Wuan23

    Wuan23

    Joined:
    Apr 12, 2023
    Posts:
    4
    In Visual Studio, enter "TextMeshPro", you will be prompted to reference the relevant dll, and the problem will be solved.