Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParameterInfo.DefaultValue may return Type.Missing #9438

Open
OwnageIsMagic opened this issue Nov 8, 2023 · 2 comments
Open

ParameterInfo.DefaultValue may return Type.Missing #9438

OwnageIsMagic opened this issue Nov 8, 2023 · 2 comments
Labels
area-System.Reflection help wanted Good for community contributors to help [up-for-grabs] Pri3 Indicates issues/PRs that are low priority

Comments

@OwnageIsMagic
Copy link

ParameterInfo.DefaultValue may return Type.Missing if parameter is optional, but no default value in metadata (probably COM interop case). Same for ParameterInfo.RawDefaultValue

See implementation

https://github.com/dotnet/runtime/blob/v7.0.13/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs#L287-L298

@issues-automation issues-automation bot added the Pri3 Indicates issues/PRs that are low priority label Nov 8, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Nov 8, 2023
@buyaa-n
Copy link
Member

buyaa-n commented Nov 9, 2023

Basically, having a default value sets the Optional attribute for the parameter. Though one can set it using [Optional] attribute even without default value. Also, it can be set with reflection emit without a default value and result Type.Missing

public void Method([Optional]string parameter) { }

@buyaa-n buyaa-n removed the untriaged New issue has not been triaged by the area owner label Nov 9, 2023
@steveharter
Copy link
Member

See also dotnet/runtime#100322

@buyaa-n buyaa-n added the help wanted Good for community contributors to help [up-for-grabs] label Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Reflection help wanted Good for community contributors to help [up-for-grabs] Pri3 Indicates issues/PRs that are low priority
Projects
None yet
Development

No branches or pull requests

3 participants