Skip to content

ParameterInfo.RawDefaultValue throws when default value is string.empty #57238

@mjkkirschner

Description

@mjkkirschner

Description

When using a metaDataLoadContext to find static methods in an assembly, invoking ParameterInfo.RawDefaultValue throws a badformat exception - I've tracked down the line of code to here:
https://github.com/dotnet/runtime/blob/main/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/Ecma/EcmaDefaultValueProcessing.cs#L18

this appears to throw when the parameter in question is an optional string with a default value of empty string ""
It looks like constantValue.Value is nil in this case. I'm not sure if it's simply an issue with empty strings in all cases or its an environment issue.

Configuration

  • Which version of .NET is the code running on? .net 4.8
  • What OS and version, and what distro if applicable? windows 10 2004
  • What is the architecture (x64, x86, ARM, ARM64)? x64
  • Do you know whether it is specific to that configuration? do not know
  • If you're using Blazor, which web browser(s) do you see this issue in? NA

Regression?

Don't know at this time.

Other information

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions