Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does System.Memory have a dependency on System.Numerics.Vectors in .Net 4.6.1 but not in .Net 4.6?

Tags:

c#

.net

nuget

These are dependencies of Nuget package System.Memory. We use older .Net framework versions and I noticed that if I use 4.6.1, there is an additional dependency on System.Numerics.Vectors (a framework DLL I think) which isn't needed in 4.5->4.6.

It seems the opposite to normal, that a newer version of .Net would require more dependencies.

Why is this, and will I see any difference e.g. in performance?

Additional dependencies

like image 252
Mr. Boy Avatar asked Sep 10 '25 03:09

Mr. Boy


1 Answers

It seems the opposite to normal, that a newer version of .Net would require more dependencies.

The System.Memory package contains libraries for the following target frameworks.

  • .NET Framework 4.6.1
  • .NET Standard 2.1
  • .NET Standard 2.0
  • .NET Standard 1.1

.NET Framework 4.5

When consuming the package in a .NET Framework 4.5 project, the System.Memory.dll from the .NET Standard 1.1 target is used, because that is the highest version that it can consume, see this reference. However, this version does not use Vector<T> or other vector types. Consequently, it does not depend on System.Numerics.Vectors.

.NET Framework 4.6

The same as for .NET Framework 4.5 applies, since .NET Standard 1.3 is the highest version that a .NET Framework 4.6 project can consume. As there is only a .NET Standard 1.1 version provided, it will fall back to that.

.NET Framework 4.6.1

When consuming the package in a .NET Framework 4.6.1 project, the corresponding version of System.Memory.dll is used. This version uses the Vector<T> type which is only available in:

  • .NET Core >= 1.0
  • .NET Standard >= 2.1 Preview
  • The System.Numerics.Vectors NuGet package

The .NET Framework 4.6.1 target has a dependency to the System.Numerics.Vectors package, because it would not be available otherwise.

[...] will I see any difference e.g. in performance?

There might be a performance benefit, since Vector<T> is a SIMD-accelerated type. It is used in a helper class for spans, where Vector.IsHardwareAccelerated is checked, so I guess there is a performance-related reason behind using Vector<T>.

Bonus Round

Why does that package even have a separate .NET Framework 4.6.1 target, if it could could use .NET Standard? That is best explained in the linked reference itself.

[...] While NuGet considers .NET Framework 4.6.1 as supporting .NET Standard 1.5 through 2.0, there are several issues with consuming .NET Standard libraries that were built for those versions from .NET Framework 4.6.1 projects. [...]

like image 130
thatguy Avatar answered Sep 12 '25 16:09

thatguy