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

Ill defined Enums file silently in Configuration Binding #36502

Closed
afcruzs opened this issue Feb 4, 2019 · 1 comment
Closed

Ill defined Enums file silently in Configuration Binding #36502

afcruzs opened this issue Feb 4, 2019 · 1 comment

Comments

@afcruzs
Copy link

afcruzs commented Feb 4, 2019

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.

@analogrelay analogrelay transferred this issue from dotnet/extensions May 15, 2020
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-Extensions-Configuration untriaged New issue has not been triaged by the area owner labels May 15, 2020
@analogrelay analogrelay added this to the Future milestone May 15, 2020
@maryamariyan maryamariyan removed the untriaged New issue has not been triaged by the area owner label Jul 1, 2020
@maryamariyan
Copy link
Member

Closing as dupe of #36502

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants