question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebJobsOptionsFactory implementation ignores the "validations" parameter

See original GitHub issue

Because the implementation of the WebJobsOptionsFactory ignores the validation, it does not perform the intended validation.

Repro steps

public class Startup : FunctionsStartup
{
    public Startup()
    {
        var config = new ConfigurationBuilder()
            .AddEnvironmentVariables();

        Configuration = config.Build();
    }

    public IConfiguration Configuration { get; }

    public override void Configure(IFunctionsHostBuilder builder)
    {
        builder.Services.AddOptions<SampleOptions>()
               .Bind(Configuration.GetSection("Sample"))
               .ValidateDataAnnotations();
    }
}

public class SampleOptions
{
    [Required]
    public string Value { get; set; }
}

Expected behavior

I expect the validation to run. Sample:Value key if the application settings are not set and OptionsValidationException is thrown.

Actual behavior

No validation is performed and the property values are not checked.

Known workarounds

public class Startup : FunctionsStartup
{
    public override void Configure(IFunctionsHostBuilder builder)
    {
        // Replace default implementation
        builder.Services.Replace(ServiceDescriptor.Transient(typeof(IOptionsFactory<>), typeof(OptionsFactory<>)));
    }
}

Related information

https://github.com/Azure/azure-webjobs-sdk/blob/f386e54e5000ddddf255f529689ab2a9c3ee78cd/src/Microsoft.Azure.WebJobs.Host/Hosting/OptionsFormatter/WebJobsOptionsFactory.cs#L28

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
selMicrosoftcommented, Mar 26, 2021

@fabiocav Any update on this? I was trying to validate options for azure functions v3 with no luck

1reaction
fabiocavcommented, Sep 14, 2020

Assigning this to the upcoming sprint

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found