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

Fix a bug where ToHashSet() is implemented in .Net 4.7.1+ System.Linq, causing failure to compile #739

Closed
wants to merge 3 commits into from

Conversation

b9chris
Copy link

@b9chris b9chris commented Dec 18, 2019

Fix a bug where:
using System.Linq;
using MoreLINQ;

Causes calls to .ToHashSet() to fail to compile, because an identical implementation exists in .Net 4.7.1+

using System.Linq;
using MoreLINQ;

Causes calls to .ToHashSet() to fail to compile, because an identical implementation exists in .Net 4.7.1+
@Orace
Copy link
Contributor

Orace commented Dec 18, 2019

#if !NET471
namespace MoreLinq

This test is at compile time, not at use time.
You can compile with 4.7 and still have the issue.

Maybe you can look what as been done in similar case (like Zip).

Anyway to fix it at user level, the README file is pretty clear about it:

https://github.com/morelinq/MoreLINQ#usage

@b9chris
Copy link
Author

b9chris commented Dec 18, 2019

This test is at compile time, not at use time.

Not sure what you mean by this. This flag is meant to prevent inclusion of the ToHashSet() extension method in 4.7.1+, and that's what it does. I've tested it - it fixes the issue.

You can compile with 4.7 and still have the issue.

I think you mean it was introduced in 4.7 not 4.7.1? Simple enough to change, I'll fix that.

Maybe you can look what as been done in similar case (like Zip).

Anyway to fix it at user level, the README file is pretty clear about it:

https://github.com/morelinq/MoreLINQ#usage

What's documented there is a workaround, not a fix. What I'm proposing is a fix.

@Orace
Copy link
Contributor

Orace commented Dec 18, 2019

This test is at compile time, not at use time.

Not sure what you mean by this. This flag is meant to prevent inclusion of the ToHashSet() extension method in 4.7.1+, and that's what it does. I've tested it - it fixes the issue.

You can compile with 4.7 and still have the issue.

I think you mean it was introduced in 4.7 not 4.7.1? Simple enough to change, I'll fix that.

The '#if' tests are done at compile time.
MoreLinq is almost distributed via nuget package that are pre-compiled.

Actually I don't know wish version of the framework is used to build the package.

Let say that the package is built in framework 4.5 (or anything not 4.7.1, like 4.7).
At compile time "NET471" will be false and the '#if' will be ignored and ToHashSet will be put in the package:

  • users of framework 4.5 will find one ToHashSet method (from MoreLinq).
  • user of framework 4.7.1 will find two ToHashSet method (MoreLinq and System.Linq).

Now, let say that the package is built in framework 4.7.1
At compile time "NET471" will be true and the '#if' will trigger, ToHashSet will not be put in the package:

  • users of framework 4.5 will find zero ToHashSet method.
  • users of framework 4.7.1 will find one ToHashSet method (System.Linq).

Hence, for nuget package distribution, nothing is fixed here.

Since the final user framework version is unknown, and because we don't want to remove any functionality for users with a framework version prior to 4.7.1, and because we don't want a MoreLinq for 3.5, one for 4.5, one for 4.7.1, etc... a workaround is advised (using alias, or static using).

Hope it's clear enough, and sorry to no be clear enough at first try.

@b9chris
Copy link
Author

b9chris commented Dec 18, 2019 via email

@viceroypenguin
Copy link
Contributor

I have wondered why this solution isn't used before. I agree with @b9chris, MoreLINQ should be able to block off certain API based on which version it is compiled with. This will make the provided work-around unnecessary.

This could also be applied to .Append() and .Prepend(), provided in the latest .net core offerings.

@Orace
Copy link
Contributor

Orace commented Jan 1, 2020

I have wondered why this solution isn't used before

The cons I see :

  • Hard to maintain.
  • Many more target frameworks.
  • Need a quick new release for any method integrated in a version of a framework (hopefully method signatures matched for now).

This will make the provided work-around unnecessary.

The workaround is still useful in case of name collision with a third-party library.

@viceroypenguin
Copy link
Contributor

On the other hand, the workaround is extra work in the case where the consumer is targeting multiple frameworks. As it is, I have multiple places where I have to include:

#if NETFX
using static MoreLinq.Extensions.AppendExtension;
#endif

If MoreLINQ handled this directly, it would be a simple using MoreLinq; in those cases.

However, I do get your point about extra work in the case of a new .net core version; they are continually adding new Enumerable features that overlap MoreLINQ.

@viceroypenguin

This comment has been minimized.

@viceroypenguin
Copy link
Contributor

@b9chris Please check out the morelinq.temp package as a proof of concept for a solution for this issue, built off of https://github.com/viceroypenguin/MoreLINQ/tree/multi-framework-support branch. If you have any comments, put them in #749.

@atifaziz
Copy link
Member

This has been superseded by PR #945.

@atifaziz atifaziz closed this Jun 25, 2023
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.

4 participants