From fd900cfa3342a3a7f4ef9c120cc6d89b72826ec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 25 May 2026 13:49:39 +0200 Subject: [PATCH 1/2] Document MTP generated code namespace conflicts in troubleshooting Adds an FAQ entry under the Microsoft.Testing.Platform.MSBuild troubleshooting section explaining how the generated SelfRegisteredExtensions and MicrosoftTestingPlatformEntryPoint types can collide with referenced types when the project name (and therefore `RootNamespace`) matches a referenced assembly's public type. Shows how to fix the conflict by overriding or clearing `RootNamespace`. Related to microsoft/testfx#7270. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- ...crosoft-testing-platform-troubleshooting.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/core/testing/microsoft-testing-platform-troubleshooting.md b/docs/core/testing/microsoft-testing-platform-troubleshooting.md index 31e6f2cbd9842..acf7bc25b9912 100644 --- a/docs/core/testing/microsoft-testing-platform-troubleshooting.md +++ b/docs/core/testing/microsoft-testing-platform-troubleshooting.md @@ -3,7 +3,7 @@ title: Microsoft.Testing.Platform (MTP) troubleshooting description: Troubleshoot MTP issues, exit codes, and known problems. author: Evangelink ms.author: amauryleve -ms.date: 02/24/2026 +ms.date: 05/25/2026 ai-usage: ai-assisted --- @@ -86,6 +86,22 @@ Manually defining an entry point (`Main`) in a test project or referencing a tes - Completely disable the transitive dependency to `Microsoft.Testing.Platform.MSBuild` by setting the `false` MSBuild property in the project that references a test project. This is needed when you reference a test project from a non-test project, for example, a console app that references a test application. +#### Generated code namespace conflicts with a referenced type + +`Microsoft.Testing.Platform.MSBuild` generates the `SelfRegisteredExtensions` and `MicrosoftTestingPlatformEntryPoint` types inside the project's `$(RootNamespace)`. By default, `RootNamespace` matches the project name, which can collide with a type of the same fully qualified name exposed by a referenced assembly. + +For example, a project named `System.Security.Cryptography.ProtectedData.Tests` ends up generating code in the `System.Security.Cryptography.ProtectedData` namespace. If the project also references the `System.Security.Cryptography.ProtectedData` NuGet package, which contains a public `ProtectedData` type under the `System.Security.Cryptography` namespace, the compiler can no longer disambiguate between the generated namespace and the referenced type, and emits errors such as `CS0118` ("'ProtectedData' is a namespace but is used like a type"). + +To resolve the conflict, override `RootNamespace` in your test project to a value that doesn't collide with any referenced type: + +```xml + + System.Security.Cryptography.ProtectedDataTests + +``` + +You can also clear `RootNamespace` entirely (``), in which case the generated types are emitted into the global namespace. + ### Microsoft.Testing.Extensions.Fakes #### Fakes error Failed to resolve profiler path from COR_PROFILER_PATH and COR_PROFILER environment variables From b9b8a2ed2caf5c76abb1a2988581edf573f1bae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 25 May 2026 14:26:04 +0200 Subject: [PATCH 2/2] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- docs/core/testing/microsoft-testing-platform-troubleshooting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/testing/microsoft-testing-platform-troubleshooting.md b/docs/core/testing/microsoft-testing-platform-troubleshooting.md index acf7bc25b9912..162a3f15bb156 100644 --- a/docs/core/testing/microsoft-testing-platform-troubleshooting.md +++ b/docs/core/testing/microsoft-testing-platform-troubleshooting.md @@ -88,7 +88,7 @@ Manually defining an entry point (`Main`) in a test project or referencing a tes #### Generated code namespace conflicts with a referenced type -`Microsoft.Testing.Platform.MSBuild` generates the `SelfRegisteredExtensions` and `MicrosoftTestingPlatformEntryPoint` types inside the project's `$(RootNamespace)`. By default, `RootNamespace` matches the project name, which can collide with a type of the same fully qualified name exposed by a referenced assembly. +`Microsoft.Testing.Platform.MSBuild` generates the `SelfRegisteredExtensions` and `TestingPlatformEntryPoint` types inside the project's `$(RootNamespace)`. By default, `RootNamespace` matches the project name, which can collide with a type of the same fully qualified name exposed by a referenced assembly. For example, a project named `System.Security.Cryptography.ProtectedData.Tests` ends up generating code in the `System.Security.Cryptography.ProtectedData` namespace. If the project also references the `System.Security.Cryptography.ProtectedData` NuGet package, which contains a public `ProtectedData` type under the `System.Security.Cryptography` namespace, the compiler can no longer disambiguate between the generated namespace and the referenced type, and emits errors such as `CS0118` ("'ProtectedData' is a namespace but is used like a type").