Skip to content

C# compiler encodes module name into anonymous type, but does not distinguish "." and "_" #1428

Description

@gafter

The C# compiler adds the module name to the encoding of an anonymous type name when generating a netmodule, but the mapping is not 1-to-1. In particular it maps "." to "_", which can cause a conflict when netmodules are combined that map to the same name under this mapping.

The VB compiler does not do this mapping, which means combining netmodules may fail due to anonymous types.

/cc @agocke @cston

Activity

  1. self-assigned this
    on Mar 20, 2015
  2. added this to the 1.2 milestone on Mar 20, 2015
  3. added
    Concept-DeterminismThe issue involves our ability to support determinism in binaries and PDBs created at build time.
    on Mar 20, 2015
  4. gafter commented on Mar 23, 2015

    @gafter
    MemberAuthor

    I suggest the following 1-to-1 mapping for turning a module name to an identifier for embedding in the name of the generated anonymous type. The mapping can also be used for producing the name of the PrivateImplementationDetails class. This mapping need only be used when we are generating a netmodule. In other cases we do not need to include the module name in the generated name.

    1. Any character that can appear in an identifier maps to itself, except Q and _.
    2. Q maps to QQ
    3. _ maps to Q_
    4. . maps to _
    5. any other character maps to Q followed by four hex digits for its unicode value.
  5. gafter commented on Mar 23, 2015

    @gafter
    MemberAuthor

    @VSadov I believe you might be looking at this.

  6. agocke commented on Mar 23, 2015

    @agocke
    Member

    I don't have a problem with the proposed solution for escaping, but FWIW I think the main issue here will be solved by not including the module name except when combining netmodules. Since very few people use netmodules the impact of the module name change should be fairly low.

  7. tmat commented on Mar 23, 2015

    @tmat
    Member

    I agree with @agocke - nobody really uses netmodules (other than Dynamics), so let's keep this as simple as possible. Just replace '.' with '/' e.g., which won't be contained in real world netmodule name since it is not a valid file name character.

  8. gafter commented on Mar 23, 2015

    @gafter
    MemberAuthor

    It sounds like the two of you agree with my proposal "This mapping need only be used when we are generating a netmodule. In other cases we do not need to include the module name in the generated name."

    However, I still think we should avoid using a mapping that is not 1-to-1. We should avoid making assumptions about the file system, so I still recommend the mapping described above.

  9. VSadov commented on Mar 23, 2015

    @VSadov
    Member

    I think replacing . with / is sufficient. We could even go as far as making module names containing "/" an error to ensure that for the set of valid module names the mapping is 1-1.

  10. tmat commented on Mar 23, 2015

    @tmat
    Member

    See MetadataHelpers:

            /// <summary>
            /// Checks that the specified name is a valid metadata String and a file name.
            /// The specification isn't entirely consistent and complete but it mentiones:
            /// 
            /// 22.19.2: "Name shall index a non-empty string in the String heap. It shall be in the format {filename}.{extension} (e.g., 'foo.dll', but not 'c:\utils\foo.dll')."
            /// 22.30.2: "The format of Name is {file name}.{file extension} with no path or drive letter; on POSIX-compliant systems Name contains no colon, no forward-slash, no backslash."
            ///          As Microsoft specific constraint.
            /// 
            /// A reasonable restriction seems to be a valid UTF8 non-empty string that doesn't contain '\0', '\', '/', ':' characters.
            /// </summary>
            internal static bool IsValidMetadataFileName(string name)
            {
                return FileNameUtilities.IsFileName(name) && IsValidMetadataIdentifier(name);
            }
  11. gafter commented on Mar 24, 2015

    @gafter
    MemberAuthor

    We're talking about the module name, which is sometimes but not always related to the metadata file name.

  12. tmat commented on Mar 24, 2015

    @tmat
    Member

    We require the module name specified via CompilationOptions to also be a valid file name (IsValidMetadataFileName true).

  13. 10 remaining items

  14. modified the milestones: 1.1, 1.2 on Jun 17, 2015
  15. removed
    4 - In ReviewA fix for the issue is submitted for review.
    on Jul 28, 2015
  16. added
    Resolution-FixedThe bug has been fixed and/or the requested behavior has been implemented
    and removed
    help wantedThe issue is "up for grabs" - add a comment if you are interested in working on it
    on Sep 21, 2015
  17. removed their assignment
    on Sep 21, 2015
  18. added a commit that references this issue on Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-CompilersBugConcept-DeterminismThe issue involves our ability to support determinism in binaries and PDBs created at build time.Pedantic ;)Resolution-FixedThe bug has been fixed and/or the requested behavior has been implementedVerified

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions