question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Framework targeting incorrect

See original GitHub issue

Hello,

There seems to be an issue with the framework targeting for the NuGet package. If you look at the package on NuGet then it appears that there are no dependencies listed. This is strange, I expected to see System.Memory somewhere.

Also, the performance improvements (that use Span) do not seem to be part of the NuGet package. The netstandard2.1 assembly in the package still has the ‘old’ signatures that use arrays, as seen below in the ILdasm screenshot.

image

I believe the error is in the way the HAS_SPAN compile time constant is defined.

Currently it is:

  <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0|net452|net462|net472'">
    <PackageReference Include="System.Memory" Version="4.5.3" />
  </ItemGroup>

  <PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1|netstandard2.1|netstandard2.0|net452|net462|net472'">
    <DefineConstants>$(DefineConstants);HAS_SPAN</DefineConstants>
  </PropertyGroup>

As far as I know the MSBuild ‘==’ operator performs an exact string match.

I believe that this is the correct way to define the dependency and constant:

  <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'
                         or '$(TargetFramework)' == 'net452'
                         or '$(TargetFramework)' == 'net462'
                         or '$(TargetFramework)' == 'net472'">
    <PackageReference Include="System.Memory" Version="4.5.3" />
  </ItemGroup>

  <PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'
                         or '$(TargetFramework)' == 'netstandard2.1'
                         or '$(TargetFramework)' == 'netstandard2.0'
                         or '$(TargetFramework)' == 'net452'
                         or '$(TargetFramework)' == 'net462'
                         or '$(TargetFramework)' == 'net472'">
    <DefineConstants>$(DefineConstants);HAS_SPAN</DefineConstants>
  </PropertyGroup>

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jvandertilcommented, Mar 10, 2020

Awesome, thanks for the quick fix 😄

0reactions
ChrisMcKeecommented, Mar 10, 2020

image from .net 4.8 project

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot .NET Framework targeting errors
To resolve the error, make sure that your application targets a .NET version that's compatible with the version that's targeted by the ...
Read more >
Targeted .NET Frameworks - Visual Studio (Windows)
Framework targeting helps guarantee that the application uses only functionality that is available in the specified framework version. For .NET ...
Read more >
Cannot Change Target Framework?
I came across this problem this morning that I can't change the target framework of an open source project. The Target framework option...
Read more >
Confusing error message when invalid target frameworks ...
In that case, the SDKs seems to be able to parse the TFMs and the build fails with an error that indicates missing...
Read more >
Incorrect Target framework in .csproj file after changing ...
NET 8 for WinUI project. Incorrect Target framework in .csproj file after changing Target framework from .NET 6.0 to.NET 7.0 in Properties.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found