Search code examples
c#typedefusingtypenametype-synonyms

using type synonym causes CS0246 The type or namespace name ... could not be found


I've named a type by short synonym. In next line I try to use this type via its this new short name somehow (doesn't matter):

using A = SomeTypeName;
using B = A;

But in line 2 the compiler doesn't see the name "A" & generates the error (see in the title). Why?


Solution

  • ECMA-334 9.4.1 Using alias directives say:

    The order in which using-alias-directives are written has no significance, and resolution of the namespace-or-type-name referenced by a using-alias-directive is not affected by the using-alias-directive itself or by other using-directives in the immediately containing compilation unit or namespace body. In other words, the namespace-or-type-name of a using-alias-directive is resolved as if the immediately containing compilation unit or namespace body had no using-directives. A using-alias-directive may however be affected by extern-alias-directives in the immediately containing compilation unit or namespace body.