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

Config generator doesn't match nullability semantics of built-in Bind #90987

Closed
stephentoub opened this issue Aug 23, 2023 · 3 comments
Closed
Assignees
Labels
area-Extensions-Configuration blocking-release bug source-generator Indicates an issue with a source generator feature
Milestone

Comments

@stephentoub
Copy link
Member

The built-in Bind method annotates the object as nullable:

public static void Bind(this IConfiguration configuration, object? instance)

and then explicitly nops if it's null:

if (instance != null)
{
    ...
}

In contrast, the code generated by the generator annotates it as non-nullable and throws an exception if it's null, changing the semantics when using the source generator.

if (obj is null)
{
    throw new ArgumentNullException(nameof(obj));
}

(It also names the parameter obj instead of instance.)

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Aug 23, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Aug 23, 2023
@stephentoub stephentoub added area-Extensions-Configuration and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Aug 23, 2023
@ghost
Copy link

ghost commented Aug 23, 2023

Tagging subscribers to this area: @dotnet/area-extensions-configuration
See info in area-owners.md if you want to be subscribed.

Issue Details

The built-in Bind method annotates the object as nullable:

public static void Bind(this IConfiguration configuration, object? instance)

and then explicitly nops if it's null:

if (instance != null)
{
    ...
}

In contrast, the code generated by the generator annotates it as non-nullable and throws an exception if it's null, changing the semantics when using the source generator.

if (obj is null)
{
    throw new ArgumentNullException(nameof(obj));
}

(It also names the parameter obj instead of instance.)

Author: stephentoub
Assignees: -
Labels:

untriaged, area-Extensions-Configuration

Milestone: -

@layomia
Copy link
Contributor

layomia commented Aug 23, 2023

Consistency is desired cc @tarekgh.

@layomia layomia added this to the 8.0.0 milestone Aug 23, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Aug 23, 2023
@layomia layomia added untriaged New issue has not been triaged by the area owner source-generator Indicates an issue with a source generator feature labels Aug 23, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Aug 23, 2023
@layomia layomia self-assigned this Aug 23, 2023
@ghost ghost added in-pr There is an active PR which will close this issue when it is merged and removed in-pr There is an active PR which will close this issue when it is merged labels Aug 30, 2023
@layomia
Copy link
Contributor

layomia commented Sep 1, 2023

Fixed for 8.0 in #91359.

@layomia layomia closed this as completed Sep 1, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Oct 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Extensions-Configuration blocking-release bug source-generator Indicates an issue with a source generator feature
Projects
None yet
Development

No branches or pull requests

2 participants