Resolve Compiler Error "Error CS0246 'Pages' could not be found"
Description
When trying to compile Test Studio project I get error CS0246: The type or namespace name 'Pages' could not be found. The error prevents me running a test list remotely or locally. The error persists even when I try to run a single test using the Execute
button.
[ Compiler ]
12:14:49 'ERROR' > C:\Test Studio Projects\TestProject27\getBaseUrl.tstest.cs(39,16) : error CS0246: The type or namespace name 'Pages' could not be found (are you missing a using directive or an assembly reference?)
12:14:49 'ERROR' > C:\Test Studio Projects\TestProject27\getBaseUrl.tstest.cs(32,17) : error CS0246: The type or namespace name 'Pages' could not be found (are you missing a using directive or an assembly reference?)
12:14:49 'INFO' > Build Failed
Cause
The code-behind files listed in the compilation errors have a namespace which doesn't match the project's namespace.
Solution
To resolve this compilation CS0246 error, follow these steps:
- Open the project in Telerik Test Studio.
- Compile the project by selecting the "Compile All" option.
-
Check the Output panel for any compilation errors. The errors are listed there.
Important!
If the local compilation is successful but you see the mendioned error when executing tests remotely via the Test Studio Scheduling setup, probably you uploaded the project to the Storage database in a corrupted state.-
If the test and code-behind file exists in the project, ensure to upload the latest fixed state of the project to the Storage database.
-
If the test and code-behind file doesn't exists in the project anymore, you will need to drop the database.
-
If the test and code-behind file exists in the project, ensure to upload the latest fixed state of the project to the Storage database.
Open the Project Settings and switch to the "Script" tab. Note the project's namespace.
- Review the tests listed in the compilation error and their coded files.
- In the code-behind file of each test listed in the compilation error, check if the namespace matches the project's namespace from the settings - replace it with the current namespace.
- Alternatively, you can change the namespace for all tests at once by opening the Project Settings, switching to the "Script" tab, and modifying the namespace there. Confirm the changes by clicking "OK".
- Compile the project again using the "Compile All" option and ensure that the compilation is now successful.
Tip
To avoid such errors ensure that you use the option to import existing tests in a Test Studio project instead of copying the files in Windows File Explorer.