-
Notifications
You must be signed in to change notification settings - Fork 291
Description
Here's a simple example with SelfRegisteredExtensions:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by Microsoft.Testing.Platform.MSBuild
// </auto-generated>
//------------------------------------------------------------------------------
namespace System.Security.Cryptography.ProtectedData.Tests
{
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static class SelfRegisteredExtensions
{
public static void AddSelfRegisteredExtensions(this global::Microsoft.Testing.Platform.Builder.ITestApplicationBuilder builder, string[] args)
{
global::Microsoft.Testing.Platform.MSBuild.TestingPlatformBuilderHook.AddExtensions(builder, args);
}
}
}Note the namespace System.Security.Cryptography.ProtectedData.Tests -- this namespace doesn't appear anywhere in the project, it's synthesized from the project name. This is generally a bad idea. The problem is this:
- System.Security.Cryptography.ProtectedData.Tests references System.Security.Cryptography.ProtectedData.
- System.Security.Cryptography.ProtectedData doesn't define that namespace -- it defines
System.Security.Cryptography - S.S.C.ProtectedData contains a public type named
ProtectedData. - Usage of
ProtectedDatain S.S.C.ProtectedData.Tests now generates errors because there's an unresolvable ambiguity between the generated namespace (System.Security.Cryptography.ProtectedData) and the type (System.Security.Cryptography.ProtectedData).
Working around this requires extern aliases, which is a fairly uncommon feature and tricky to use.
My recommendation here would be to never synthesize new namespace names. If you're generating code for a particular type, you could consider putting more code inside that type's namespace. You could also use a namespace of your own, e.g. Microsoft.Testing.Platform. You could even put things in the global namespace. But synthesizing new namespaces is a recipe for tricky conflicts.