Skip to content

Conversation

@steveharter
Copy link
Contributor

Fixes #95789

This fixes a regression for cases where ServiceDescriptor.ImplementationInstance\Type\Factory is called for code that is not servicekey-aware. Instead of throwing, null is returned.

This will be backported to 8.0.

@steveharter steveharter self-assigned this Jul 31, 2024
@steveharter steveharter added this to the 9.0.0 milestone Jul 31, 2024
@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).


private static void ThrowKeyedDescriptor() => throw new InvalidOperationException(SR.KeyedDescriptorMisuse);

private static void ThrowNonKeyedDescriptor() => throw new InvalidOperationException(SR.NonKeyedDescriptorMisuse);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't throw when accessing on non-leyed property when the descriptor is kedyed, shoud we also remove this, to be consistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering about that as well. The original issue was a backwards compat issue with existing APIs so not throwing there makes sense. Throwing for the new APIs I think is OK and desired to help catch issues (as originally intended).

Other than consistency, can you think of a scenario where we would want to return null for the new APIs?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope it's only for consistency's sake. It's fine to me to throw here otherwise

Copy link
Contributor

@buyaa-n buyaa-n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nits on docs, otherwise LGTM

@steveharter
Copy link
Contributor Author

/backport to release/8.0-staging

@github-actions
Copy link
Contributor

Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/10512853943

@github-actions
Copy link
Contributor

@steveharter backporting to release/8.0-staging failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: Return null instead of throwing in ServiceDescriptor.ImplementationInstance\Type\Factory if a keyed service
Using index info to reconstruct a base tree...
M	src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ServiceDescriptor.cs
M	src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.Tests/ServiceCollectionKeyedServiceExtensionsTest.cs
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.Tests/ServiceCollectionKeyedServiceExtensionsTest.cs
Auto-merging src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ServiceDescriptor.cs
CONFLICT (content): Merge conflict in src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ServiceDescriptor.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config advice.mergeConflict false"
Patch failed at 0001 Return null instead of throwing in ServiceDescriptor.ImplementationInstance\Type\Factory if a keyed service
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

@github-actions
Copy link
Contributor

@steveharter an error occurred while backporting to release/8.0-staging, please check the run log for details!

Error: git am failed, most likely due to a merge conflict.

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

Projects

None yet

3 participants