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

Skip unnecessary BCL package reference if targeting .NET 6 or later #857

Merged
merged 1 commit into from
Feb 23, 2023

Conversation

asimmon
Copy link
Contributor

@asimmon asimmon commented Feb 23, 2023

As mentioned in #852, I would like to introduce multi-targeting only to skip an unnecessary package reference (Microsoft.Bcl.AsyncInterfaces) on .NET 6 and later, because it's already included by default.

A (positive?) side effect of targeting net6.0 is that a few warnings appeared in existing code because of new nullable reference types annotations. For instance, IServiceProvider.GetService(Type serviceType):

  • Returns object in netstandard2.0
  • Returns object? in net6.0

At runtime, the behavior is the same. It's just that Microsoft added more hints to prevent null reference exceptions. I had to fix these warnings, and that explains the number of changes.

While fixing these warnings in Mediator.cs, I also added:

  • Missing InvalidOperationException if we can't create the wrapper for stream requests handlers (instead of null-ref ex),
  • More consistency in how wrappers are cached in their respective concurrent dictionaries (static delegates everywhere for better memory usage),
  • More consistency in InvalidOperationException messages

@asimmon asimmon marked this pull request as ready for review February 23, 2023 05:19
@asimmon
Copy link
Contributor Author

asimmon commented Feb 23, 2023

😕Seems like there is a flaky test that relies on timing (MediatR.Tests.NotificationPublisherTests.Should_handle_sequentially_by_default). I guess that this is to test parallel notification handlers against sequential notification handlers, but on GitHub agents this can be unreliable.

Copy link
Owner

@jbogard jbogard left a comment

Choose a reason for hiding this comment

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

Were the additional null checks a side effect of .NET 6?

@asimmon
Copy link
Contributor Author

asimmon commented Feb 23, 2023

Were the additional null checks a side effect of .NET 6?

Yes. Basically it adds more precise hints on the existing runtime behavior. I think it's a positive thing, it puts in evidence paths that could eventually throw a null-reference exception. GetService is a good example. In the current master state, it could return null but there's no warning whatsoever.

@jbogard jbogard merged commit cbb16f9 into jbogard:master Feb 23, 2023
@asimmon asimmon deleted the skip-bcl-on-net6-and-later branch February 23, 2023 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants