Skip to content

FieldBuilder.SetValue for static init-only fields in .NET Core 3.0+ #3851

@n9

Description

@n9

The documentation says:

> This method is currently not supported. As a workaround, retrieve the <xref:System.Reflection.FieldInfo> by reflecting on the finished type and call <xref:System.Reflection.FieldInfo.SetValue%2A> to set the value of the field.

For static init-only fields, this workaround was working in .NET Framework, however this is no longer supported in .NET Core 3.0+ (see dotnet/runtime#11571 (comment)).

So, how to initialize static init-only field of dynamic type in .NET Core 3.0+?
It would be great if the documentation will provide this hint:)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions