Namespace TMPro not found in Test Runner test

When using Test Runner for a project containing TextMeshPro field, there is an error in Unity: error CS0246: The type or namespace name `TMPro’ could not be found. Are you missing an assembly reference?

Steps to reproduce:

  • Create a new project.
  • Add a TextMeshPro field to SampleScene
  • Create a PlayMode test in Test Runner window
  • In Visual Studio, in the test file, add “using TMPro;” statement
  • It’s underlined red.
  • In Solution Explorer, in the test project, add a reference to Unity.TextMeshPro
  • It’s still underlined red.

Is there a way to get rid of that error? I have it in 2018.1 and in 2018.2

I am assuming that you have installed the latest TMP UPM package (version 1.2.4) via the Package Manager UI and subsequently imported the TMP Essential Resources?

(1) I just created a new project in Unity 2018.2.
(2) Made sure the TMP UPM package we already installed which it is for Unity 2018.2.
(3) Imported the TMP Essential Resources.
(4) Created a test folder.
(5) Open the Test Runner and use Create Test Script in current folder (the one I created above)
(6) Adding the using TMPro;

The steps above worked as expected on my end.

Make sure that you are using the latest version of Visual Studio 2017 which is 15.7.5. If not, see if you get the same behavior with this latest release. If you are doing this in the same (new project), make sure you delete any solution created in that project and the Library folder.

Let me know what happens.

I have now Unity Personal 2018.2.0f2, VisualStudio Community 15.7.5 and TextMeshPro 1.2.4
After updating VS to this version, nothing changed, there is the same error.

(1) I created a brand new project in 2018.2.0f2 (those previous I mentioned before were imported from 2018.1).
(2) TMPro was already installed in Package Manager.
(3) I clicked “Import TMP essentials” before adding a TMPro field
(4) Selected the root (Assets), opened Test Runner and clicked on “Create PlayMode test assembly folder” (with name MyTests2)
(5) Then I created the script and opened it in VS.
(6) Tried to add “using TMPro”, intellisense doesn’t suggest TMPro, after typing manually it’s underlined in red.

I don’t know if it matters, but if I click in VS on “MyTests2/References” there is no Unity.TextMeshPro reference. However, in Assembly-CSharp/References there is such reference.

The step that I missed which is causing the issue is related to the use of an Assembly Definition in this created test folder.

The solution is to manually edit the .asmdef to add a reference to the Unity.TextMeshPro assembly.

In order to do so, select the file and use the context menu “Show in Explorer” and then open the file in some text editor to make the following changes…

{
    "name": "Tests",
    "references": [ "Unity.TextMeshPro" ],
    "optionalUnityReferences": [ "TestAssemblies" ]
}
7 Likes

This is working now, thanks!

1 Like

I am sorry, where do I find the .asmdef file ?

When the Test Runner creates the folder, it adds the .asmdef file in that folder.

So better fix then having to edit the file for each script. It looks like you need to update Visual studio, because it is trying to build the references for the project, but is looking for them in the old location(aka not the new “Packages” folder in your project folder, but in your user folder?). Once updated It should rebuild for the project, if not maybe hit rebuild, or take out the “Unity.TextMeshPro.csproj” and “Unity.TextMeshPro.Editor.csproj” files from the project folder. Hope this helped someone else.

1 Like

work like a charm

work like a charm, thanks so much

I had a similar problem, but when creating the test folder it encouraged me to create a game assembly - so similar steps of embedding the reference to text mesh pro in the game assembly actually fixed my issue (which is not the test runner file.)