Sergio0694 / PolySharp

PolySharp provides generated, source-only polyfills for C# language features, to easily use all runtime-agnostic features downlevel. Add a reference, set your C# version to latest and have fun! 🚀
MIT License
1.75k stars 45 forks source link

System.Range not included in NetFramework 4.6.2 projects #96

Open rezanid opened 7 months ago

rezanid commented 7 months ago

Description (optional)

I have several NetFramework 4.6.2 projects in a solution and when compiling them, I noticed build issues when using the new range syntax for strings. I replaced the usages of range with SubString calls and compiled the solution then opened the compiled assembly and noticed that the System.Range has not been included.

image

Maybe I'm doing something wrong? but, I wasn't able to find anything about this in the docs.

Reproduction Steps

  1. Build a .Net Framework 4.6.2 Library project.
  2. Use range syntax in a method (e.g. "string"[..2]).
  3. Build the project.
  4. Build will fails, saying that System.Range does not exist.
  5. Replace the range with SubString.
  6. Build again.
  7. Use a decompiler to open the assembly.
  8. You will notice System.Range is not included.

Expected Behavior

The assembly should contain System.Range and the range syntax should work.

Actual Behavior

If range syntax is used the build will fail. If range syntax is not used, build is successful, but the System.Range won't be included.

System info

This section should contain useful info such as:

Additional context (optional)

I did not notice any messages from Polysharp in the build log, even when building with detailed logging.

saucecontrol commented 6 months ago

I started seeing this today, in a project that had previously been working. Getting an error from the analyzer saying I need to use at least C# 8

image

Which I most certainly am

image

Doesn't work from VS (17.10P2) or from dotnet CLI (SDK 8.0.200).

Unfortunately I did a full Patch Tuesday update, including grabbing the new VS preview, so I don't know which thing broke it.

saucecontrol commented 6 months ago

Ah, looks like I probably hadn't built the net46 target since applying the fixer to use range syntax this morning, so the software updates were unrelated.

Reverting that, I do still see the warning node, but the types are being generated. The list includes Index.g.cs, but Range.g.cs is missing.

saucecontrol commented 6 months ago

...And it's mentioned on the readme under a note for .NET 3.5. If you don't have ValueTuple, you don't get Range. Adding a reference to the ValueTuple package fixes it right up.

Sergio0694 commented 6 months ago

🦆