Repository navigation
C# compiler encodes module name into anonymous type, but does not distinguish "." and "_" #1428
Description
Activity
- addedConcept-DeterminismThe issue involves our ability to support determinism in binaries and PDBs created at build time.The issue involves our ability to support determinism in binaries and PDBs created at build time.
on Mar 20, 2015 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.
- Any character that can appear in an identifier maps to itself, except
Qand_. Qmaps toQQ_maps toQ_.maps to_- any other character maps to
Qfollowed by four hex digits for its unicode value.
- Any character that can appear in an identifier maps to itself, except
@VSadov I believe you might be looking at this.
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.
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.
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.
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.
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); }
We're talking about the module name, which is sometimes but not always related to the metadata file name.
We require the module name specified via CompilationOptions to also be a valid file name (IsValidMetadataFileName true).
10 remaining items
- added a commit that references this issue
on Apr 30, 2015 - added4 - In ReviewA fix for the issue is submitted for review.A fix for the issue is submitted for review.
on Jun 17, 2015 - added a commit that references this issue
on Jun 27, 2015 - removed4 - In ReviewA fix for the issue is submitted for review.A fix for the issue is submitted for review.
on Jul 28, 2015 - addedResolution-FixedThe bug has been fixed and/or the requested behavior has been implementedThe bug has been fixed and/or the requested behavior has been implementedand removedhelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on itThe issue is "up for grabs" - add a comment if you are interested in working on it
on Sep 21, 2015 - added a commit that references this issue
on Aug 18, 2026
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