Skip to content

Ill defined Enums file silently in Configuration Binding #36502

Closed

Description

@afcruzs

When binding a configuration which contains an Enum type it fails silently if the enum is not well defined. In general, if the binding fails it will just fail silently and that part of the configuration is not binded and proceed. I want to catch this errors to prevent runtime errors due to misconfigurations.

Is it possible to catch that error or add validation logic somewhere?, or, is it possible to allow control of whether to fail silently or not?

The silent pass happens here and in other places (depending on the collection type you're binding).

Lets say I have the following json configuration file:

{
   "Config": [
        {
          "Color": "Red"
        },
        {
          "Color": "Dog"
        }
    ]
}

And I'm trying to bind it to the following class:

public class MyConfiguration
{
  public IList<Color> Config { get; set }
}

Where Color is an enum defined somewhere:

public Enum
{
  Red,
  Green,
  Blue,
}

If I set "Dog" the enum parse will fail and thus that section of the config will be ignored. I would rather catch that error and let know the user his/her configuration is not well defined.

Activity

  1. added
    untriaged
    on May 15, 2020
  2. added this to the Future milestone on May 15, 2020
  3. removed
    untriaged
    on Jul 1, 2020
  4. maryamariyan commented on Oct 8, 2020

    @maryamariyan
    Contributor

    Closing as dupe of #36502

  5. ghost locked as resolved and limited conversation to collaborators on Dec 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions