-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Binding collection is not working for options in .net 7.0.1 - it is working in version 7.0.0 and below #79904
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
@msmolka thanks for providing the code with tests. Can you provide a small repro that highlights what is happening and what you would expect to happen? |
This issue has been marked |
Tagging subscribers to this area: @dotnet/ncl Issue DetailsDescriptionI have following code for options: Above code works properly in version 7.0.0 and below However after applying 7.0.1 patch it stopped working. Reproduction StepsGrab repo at point: 2 test are failing for .net 7.0 (only after applying patch). They are passing before applying 7.0.1 patch Expected behaviorThere are no braking changes in patch version Actual behaviorBreaking changes in patch version Regression?it is working on version 7.0.0. and below Known WorkaroundsConfigurationNo response Other informationNo response
|
Tagging subscribers to this area: @dotnet/area-extensions-options Issue DetailsDescriptionI have following code for options: Above code works properly in version 7.0.0 and below However after applying 7.0.1 patch it stopped working. Reproduction StepsGrab repo at point: 2 test are failing for .net 7.0 (only after applying patch). They are passing before applying 7.0.1 patch Expected behaviorThere are no braking changes in patch version Actual behaviorBreaking changes in patch version Regression?it is working on version 7.0.0. and below Known WorkaroundsConfigurationNo response Other informationNo response
|
I am hitting the same issue. The setter will be executed only when the corresponding property exists in the configuration source. public class MyOptions
{
private int _numOfRetries;
public int NumOfRetries
{
get => _numOfRetries;
set => _numOfRetries = value != 0 ? value : 5;
}
}
var myOptions = configuration.GetSection("MyOptions").Get<MyOptions>(); In .NET 6, when the |
@msmolka @gao-artur could you please provide a complete code sample reproducing the issue? Thanks! Also, could you try the same repo with the following version of the library and let me know? <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0-alpha.1.22578.1" /> from the nuget feed: <add key="dotnet8" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json" /> |
Hey @tarekgh, here is the test to reproduce the breaking change/regression: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
</ItemGroup>
</Project> using System.Collections.Generic;
using Microsoft.Extensions.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace TestProject2;
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
var configuration = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
["MyOptions:Option1"] = "3"
})
.Build();
var myOptions = configuration.GetSection("MyOptions").Get<MyOptions>();
Assert.IsNotNull(myOptions);
// exists in configuration and properly sets the property
Assert.AreEqual(3, myOptions.Option1);
// doesn't exist in configuration. In net6.0 the setter sets default value '2' but not in net7.0
Assert.AreEqual(2, myOptions.Option2);
}
}
public class MyOptions
{
private int _option1;
private int _option2;
public int Option1
{
get => _option1;
set => _option1 = value == 0 ? 1 : value;
}
public int Option2
{
get => _option2;
set => _option2 = value == 0 ? 2 : value;
}
}
|
The issue also persists in the |
@gao-artur thanks for providing the repro. I see your repro code is failing on .NET |
Hi, here is working repo, but during creation I found that bug is in fact in Microsoft.Extensions.Configuration.Binder package. When package is 7.0.0 and below all is working. 7.0.1 and above not. Repo will throw exception in v 7.0.1 and will work below. |
Thanks @msmolka I'll try your repo too. I already created a local fix for @gao-artur issue. |
Fixed by #80562 |
Description
I have following code for options:
https://github.com/msmolka/ZNetCS.AspNetCore.IPFiltering/blob/c4f6d097351e2d40126cd4be67d506e4fae6b1b3/src/ZNetCS.AspNetCore.IPFiltering/OptionBase.cs
Above code works properly in version 7.0.0 and below
However after applying 7.0.1 patch it stopped working.
We had to change code to following:
https://github.com/msmolka/ZNetCS.AspNetCore.IPFiltering/blob/4434801b441d3d8ba93c00649be148df52b43ed5/src/ZNetCS.AspNetCore.IPFiltering/OptionBase.cs
Reproduction Steps
Grab repo at point:
https://github.com/msmolka/ZNetCS.AspNetCore.IPFiltering/tree/f60a40de740681ed58cbd9906dcf46466f7513e6
2 test are failing for .net 7.0 (only after applying patch). They are passing before applying 7.0.1 patch
Expected behavior
There are no braking changes in patch version
Actual behavior
Breaking changes in patch version
Regression?
it is working on version 7.0.0. and below
Known Workarounds
https://github.com/msmolka/ZNetCS.AspNetCore.IPFiltering/blob/master/src/ZNetCS.AspNetCore.IPFiltering/OptionBase.cs
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: