question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

REQ: Don't throw for a class with member names differing by only by casing

See original GitHub issue

Steps to reproduce

Add-Type -TypeDefinition 'public enum Testing { Yes, yes }'
[Testing] | Get-Member -Static

Expected behavior

Either get both “Yes” members, or just the last one processed. Mainly I’d expect it not to throw.

Actual behavior

Get-Member : The field or property: "yes" for type: "Testing" differs only in letter casing from the field or property: "Yes". The type must be Common Language Specification (CLS) compliant.
At line:1 char:13
+ [Testing] | Get-Member -Static
+             ~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Get-Member], ExtendedTypeSystemException
+ FullyQualifiedErrorId : NotACLSComplaintField,Microsoft.PowerShell.Commands.GetMemberCommand

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.2
PSEdition                      Core
GitCommitId                    7.0.0-preview.2
OS                             Microsoft Windows 10.0.18362
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Other

Here’s where it throws in DotNetAdapter.

I ran into this while writing something that uses dnlib. Their MethodAttributes enum has two values for PInvokeImpl (~I’d guess they had the one with the incorrect casing originally and just added one with the right casing as to not break anyone. That’s just a guess though~ Actually looking at the rest, I think it’s because they’re using both the System.Reflection names as well as the EMCA spec names.)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:33 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
SteveL-MSFTcommented, Oct 28, 2019

@PowerShell/powershell-committee reviewed this, we propose the following behavior:

  • if there is a single member, the casing you provide doesn’t matter and we will continue to match on that member
  • if there are two members differing by casing, and you provide casing that matches one of them exactly, we will return that member
  • if there are two members differing by casing, and you provide casing that doesn’t match any, then we will return an new error indicating such (nothing about CLS compliance)
3reactions
0xd4dcommented, Oct 21, 2019

I think most .NET libraries are not CLS compliant and the reason is simple, most people use C#.

PowerShell shouldn’t throw in this case, it’s fine to say this is undefined behavior as long as it doesn’t throw.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'File name differs from already included file name only in ...
The thing is, it compiles just fine on Mac and Linux, but throws this error on Windows. If it helps, forceConsistentCasingInFileNames is enabled ......
Read more >
Is using parameter names that differ from type names only ...
The language itself is offering us a perfectly clear, unambiguous universally recognizable way of indicating we are dealing with a class member.
Read more >
Methods and field names should not be the same or differ ...
This rule raises an issue when there is a method and a field in a class with names that differ only by capitalization....
Read more >
ProGuard Manual: Usage
By default, ProGuard shrinks the code: it removes all unused classes and class members. It only keeps the ones listed by the various...
Read more >
Model Binding in ASP.NET Core
Learn how model binding in ASP.NET Core works and how to customize its behavior.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found