Skip to content

7.0: update target framework from net461 to netcoreapp3.1 #971

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

Merged
merged 1 commit into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions projects/RabbitMQ.Client/RabbitMQ.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;netstandard2.0</TargetFrameworks>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AssemblyTitle>RabbitMQ Client Library for .NET</AssemblyTitle>
Expand All @@ -28,6 +28,7 @@
<PackageOutputPath>..\..\packages</PackageOutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CodeAnalysisRuleSet>RabbitMQ.ruleset</CodeAnalysisRuleSet>
<LangVersion>latest</LangVersion>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would not set the language version to latest. Because that allows you to use language features that might not be supported by the TFMs chosen here. If you leave it blank you get automatically the proper language version supported by the TFM intersection

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't "The compiler accepts syntax from the latest released version of the compiler" mean it will always choose the latest possible whatever framework version we selected?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, it will choose the the latest version the compiler knows about, overriding the version that would have been picked by the compiler based on the TFM.

@danielmarbach is right that it should not be set to get the automatic behavior that we want here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well that's wrong then, sorry. I'll update it in one of my next PRs. Thanks for the review

</PropertyGroup>

<PropertyGroup Condition="'$(CONCOURSE_CI_BUILD)' == 'true'">
Expand Down Expand Up @@ -57,7 +58,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="2.3.0" PrivateAssets="All" />
Expand Down
8 changes: 2 additions & 6 deletions projects/RabbitMQ.Client/client/impl/TcpClientAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@ public virtual async Task ConnectAsync(string host, int port)
await ConnectAsync(ep, port).ConfigureAwait(false);
}

public virtual async Task ConnectAsync(IPAddress ep, int port)
public virtual Task ConnectAsync(IPAddress ep, int port)
{
AssertSocket();
#if NET461
await Task.Run(() => _sock.Connect(ep, port)).ConfigureAwait(false);
#else
await _sock.ConnectAsync(ep, port).ConfigureAwait(false);
#endif
return _sock.ConnectAsync(ep, port);
}

public virtual void Close()
Expand Down
76 changes: 1 addition & 75 deletions projects/RabbitMQ.Client/util/NetworkOrderDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,124 +9,50 @@ internal static class NetworkOrderDeserializer
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static double ReadDouble(ReadOnlySpan<byte> span)
{
#if NETFRAMEWORK
if (span.Length < 8)
{
throw new ArgumentOutOfRangeException(nameof(span), "Insufficient length to decode Double from memory.");
}
ulong val = ReadUInt64(span);
#elif NETSTANDARD
ulong val = BinaryPrimitives.ReadUInt64BigEndian(span);
#endif
return Unsafe.As<ulong, double>(ref val);
return BitConverter.Int64BitsToDouble(BinaryPrimitives.ReadInt64BigEndian(span));
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static short ReadInt16(ReadOnlySpan<byte> span)
{
#if NETFRAMEWORK
if (span.Length < 2)
{
throw new ArgumentOutOfRangeException(nameof(span), "Insufficient length to decode Int16 from memory.");
}

return (short)ReadUInt16(span);
#elif NETSTANDARD
return BinaryPrimitives.ReadInt16BigEndian(span);
#endif
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static int ReadInt32(ReadOnlySpan<byte> span)
{
#if NETFRAMEWORK
if (span.Length < 4)
{
throw new ArgumentOutOfRangeException(nameof(span), "Insufficient length to decode Int32 from memory.");
}

return (int)ReadUInt32(span);
#elif NETSTANDARD
return BinaryPrimitives.ReadInt32BigEndian(span);
#endif
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static long ReadInt64(ReadOnlySpan<byte> span)
{
#if NETFRAMEWORK
if (span.Length < 8)
{
throw new ArgumentOutOfRangeException(nameof(span), "Insufficient length to decode Int64 from memory.");
}

return (long)ReadUInt64(span);
#elif NETSTANDARD
return BinaryPrimitives.ReadInt64BigEndian(span);
#endif
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static float ReadSingle(ReadOnlySpan<byte> span)
{
#if NETFRAMEWORK
if (span.Length < 4)
{
throw new ArgumentOutOfRangeException(nameof(span), "Insufficient length to decode Single from memory.");
}

uint num = ReadUInt32(span);
#elif NETSTANDARD
uint num = BinaryPrimitives.ReadUInt32BigEndian(span);
#endif
return Unsafe.As<uint, float>(ref num);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static ushort ReadUInt16(ReadOnlySpan<byte> span)
{
#if NETFRAMEWORK
if (span.Length < 2)
{
throw new ArgumentOutOfRangeException(nameof(span), "Insufficient length to decode UInt16 from memory.");
}

return (ushort)((span[0] << 8) | span[1]);
#elif NETSTANDARD
return BinaryPrimitives.ReadUInt16BigEndian(span);
#endif
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static uint ReadUInt32(ReadOnlySpan<byte> span)
{
#if NETFRAMEWORK
if (span.Length < 4)
{
throw new ArgumentOutOfRangeException(nameof(span), "Insufficient length to decode UInt32 from memory.");
}

return (uint)((span[0] << 24) | (span[1] << 16) | (span[2] << 8) | span[3]);
#elif NETSTANDARD
return BinaryPrimitives.ReadUInt32BigEndian(span);
#endif
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static ulong ReadUInt64(ReadOnlySpan<byte> span)
{
#if NETFRAMEWORK
if (span.Length < 8)
{
throw new ArgumentOutOfRangeException(nameof(span), "Insufficient length to decode UInt64 from memory.");
}

uint num1 = (uint)((span[0] << 24) | (span[1] << 16) | (span[2] << 8) | span[3]);
uint num2 = (uint)((span[4] << 24) | (span[5] << 16) | (span[6] << 8) | span[7]);
return ((ulong)num1 << 32) | num2;
#elif NETSTANDARD
return BinaryPrimitives.ReadUInt64BigEndian(span);
#endif
}
}
}
111 changes: 1 addition & 110 deletions projects/RabbitMQ.Client/util/NetworkOrderSerializer.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Buffers.Binary;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace RabbitMQ.Util
{
Expand All @@ -10,158 +9,50 @@ internal static class NetworkOrderSerializer
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void WriteDouble(Span<byte> span, double val)
{
#if NETFRAMEWORK
if (span.Length < 8)
{
throw new ArgumentOutOfRangeException(nameof(span), "Insufficient length to write Double to memory.");
}

long tempVal = BitConverter.DoubleToInt64Bits(val);
span[0] = (byte)((tempVal >> 56) & 0xFF);
span[1] = (byte)((tempVal >> 48) & 0xFF);
span[2] = (byte)((tempVal >> 40) & 0xFF);
span[3] = (byte)((tempVal >> 32) & 0xFF);
span[4] = (byte)((tempVal >> 24) & 0xFF);
span[5] = (byte)((tempVal >> 16) & 0xFF);
span[6] = (byte)((tempVal >> 8) & 0xFF);
span[7] = (byte)(tempVal & 0xFF);
#elif NETSTANDARD
long tempVal = BitConverter.DoubleToInt64Bits(val);
BinaryPrimitives.WriteInt64BigEndian(span, tempVal);
#endif
BinaryPrimitives.WriteInt64BigEndian(span, BitConverter.DoubleToInt64Bits(val));
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void WriteInt16(Span<byte> span, short val)
{
#if NETFRAMEWORK
if (span.Length < 2)
{
throw new ArgumentOutOfRangeException(nameof(span), "Insufficient length to write Int16 to memory.");
}

span[0] = (byte)((val >> 8) & 0xFF);
span[1] = (byte)(val & 0xFF);
#elif NETSTANDARD
BinaryPrimitives.WriteInt16BigEndian(span, val);
#endif
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void WriteInt32(Span<byte> span, int val)
{
#if NETFRAMEWORK
if (span.Length < 4)
{
throw new ArgumentOutOfRangeException(nameof(span), "Insufficient length to write Int32 to memory.");
}

span[0] = (byte)((val >> 24) & 0xFF);
span[1] = (byte)((val >> 16) & 0xFF);
span[2] = (byte)((val >> 8) & 0xFF);
span[3] = (byte)(val & 0xFF);
#elif NETSTANDARD
BinaryPrimitives.WriteInt32BigEndian(span, val);
#endif
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void WriteInt64(Span<byte> span, long val)
{
#if NETFRAMEWORK
if (span.Length < 8)
{
throw new ArgumentOutOfRangeException(nameof(span), "Insufficient length to write Int64 to memory.");
}

span[0] = (byte)((val >> 56) & 0xFF);
span[1] = (byte)((val >> 48) & 0xFF);
span[2] = (byte)((val >> 40) & 0xFF);
span[3] = (byte)((val >> 32) & 0xFF);
span[4] = (byte)((val >> 24) & 0xFF);
span[5] = (byte)((val >> 16) & 0xFF);
span[6] = (byte)((val >> 8) & 0xFF);
span[7] = (byte)(val & 0xFF);
#elif NETSTANDARD
BinaryPrimitives.WriteInt64BigEndian(span, val);
#endif
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void WriteSingle(Span<byte> span, float val)
{
#if NETFRAMEWORK
if (span.Length < 4)
{
throw new ArgumentOutOfRangeException(nameof(span), "Insufficient length to write Single to memory.");
}

int tempVal = Unsafe.As<float, int>(ref val);
span[0] = (byte)((tempVal >> 24) & 0xFF);
span[1] = (byte)((tempVal >> 16) & 0xFF);
span[2] = (byte)((tempVal >> 8) & 0xFF);
span[3] = (byte)(tempVal & 0xFF);
#elif NETSTANDARD
int tempVal = Unsafe.As<float, int>(ref val);
BinaryPrimitives.WriteInt32BigEndian(span, tempVal);
#endif
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void WriteUInt16(Span<byte> span, ushort val)
{
#if NETFRAMEWORK
if (span.Length < 2)
{
throw new ArgumentOutOfRangeException(nameof(span), "Insufficient length to write UInt16 to memory.");
}

span[0] = (byte)((val >> 8) & 0xFF);
span[1] = (byte)(val & 0xFF);
#elif NETSTANDARD
BinaryPrimitives.WriteUInt16BigEndian(span, val);
#endif
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void WriteUInt32(Span<byte> span, uint val)
{
#if NETFRAMEWORK
if (span.Length < 4)
{
throw new ArgumentOutOfRangeException(nameof(span), "Insufficient length to write UInt32 to memory.");
}

span[0] = (byte)((val >> 24) & 0xFF);
span[1] = (byte)((val >> 16) & 0xFF);
span[2] = (byte)((val >> 8) & 0xFF);
span[3] = (byte)(val & 0xFF);
#elif NETSTANDARD
BinaryPrimitives.WriteUInt32BigEndian(span, val);
#endif
}


[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void WriteUInt64(Span<byte> span, ulong val)
{
#if NETFRAMEWORK
if (span.Length < 8)
{
throw new ArgumentOutOfRangeException(nameof(span), "Insufficient length to write UInt64 from memory.");
}

span[0] = (byte)((val >> 56) & 0xFF);
span[1] = (byte)((val >> 48) & 0xFF);
span[2] = (byte)((val >> 40) & 0xFF);
span[3] = (byte)((val >> 32) & 0xFF);
span[4] = (byte)((val >> 24) & 0xFF);
span[5] = (byte)((val >> 16) & 0xFF);
span[6] = (byte)((val >> 8) & 0xFF);
span[7] = (byte)(val & 0xFF);
#elif NETSTANDARD
BinaryPrimitives.WriteUInt64BigEndian(span, val);
#endif
}
}
}
3 changes: 2 additions & 1 deletion projects/Unit/Unit.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;netstandard2.0</TargetFrameworks>
<AssemblyOriginatorKeyFile>../rabbit.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down