Skip to content

Commit

Permalink
Merge pull request #1033 from thompson-tomo/chore/#1032_AddNet7and8
Browse files Browse the repository at this point in the history
Add .NET 6 and 8 targets and drop dependencies
  • Loading branch information
AArnott authored Apr 30, 2024
2 parents 0d588e2 + 8ffa668 commit e269ac6
Show file tree
Hide file tree
Showing 26 changed files with 1,415 additions and 30 deletions.
9 changes: 4 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>

<MessagePackVersion>2.5.108</MessagePackVersion>
<MicroBuildVersion>2.0.149</MicroBuildVersion>
<VisualStudioThreadingVersion>17.9.28</VisualStudioThreadingVersion>
Expand All @@ -25,14 +24,14 @@
<PackageVersion Include="Microsoft.VisualStudio.Validation" Version="17.8.8" />
<PackageVersion Include="Nerdbank.Streams" Version="2.10.69" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.1" />
<PackageVersion Include="System.Collections.Immutable" Version="7.0.0" />
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="8.0.0" />
<PackageVersion Include="System.Collections.Immutable" Version="6.0.0" />
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="6.0.1" />
<PackageVersion Include="System.IO.Pipelines" Version="7.0.0" />
<PackageVersion Include="System.IO.Pipes" Version="4.3.0" />
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="System.Text.Json" Version="7.0.3" />
<PackageVersion Include="System.Text.Encodings.Web" Version="7.0.0" />
<PackageVersion Include="System.Threading.Tasks.Dataflow" Version="7.0.0" />
<PackageVersion Include="System.Threading.Tasks.Dataflow" Version="6.0.0" />
<PackageVersion Include="System.ValueTuple" Version="4.5.0" />
<PackageVersion Include="xunit.combinatorial" Version="1.6.24" />
<PackageVersion Include="xunit.runner.console" Version="2.5.3" />
Expand All @@ -54,4 +53,4 @@
<ItemGroup>
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>
</Project>
</Project>
3 changes: 3 additions & 0 deletions src/StreamJsonRpc/Exceptions/BadRpcHeaderException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public BadRpcHeaderException(string? message, Exception? innerException)
/// </summary>
/// <param name="info">Serialization info.</param>
/// <param name="context">Streaming context.</param>
#if NET8_0_OR_GREATER
[Obsolete]
#endif
protected BadRpcHeaderException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
Expand Down
3 changes: 3 additions & 0 deletions src/StreamJsonRpc/Exceptions/ConnectionLostException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public ConnectionLostException(string? message, Exception? innerException)
/// </summary>
/// <param name="info">Serialization info.</param>
/// <param name="context">Streaming context.</param>
#if NET8_0_OR_GREATER
[Obsolete]
#endif
protected ConnectionLostException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
Expand Down
3 changes: 3 additions & 0 deletions src/StreamJsonRpc/Exceptions/RemoteInvocationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public RemoteInvocationException(string? message, int errorCode, Exception inner
/// </summary>
/// <param name="info">Serialization info.</param>
/// <param name="context">Streaming context.</param>
#if NET8_0_OR_GREATER
[Obsolete]
#endif
protected RemoteInvocationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Expand Down
6 changes: 6 additions & 0 deletions src/StreamJsonRpc/Exceptions/RemoteMethodNotFoundException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ internal RemoteMethodNotFoundException(string? message, string targetMethod, Jso
/// </summary>
/// <param name="info">Serialization info.</param>
/// <param name="context">Streaming context.</param>
#if NET8_0_OR_GREATER
[Obsolete]
#endif
protected RemoteMethodNotFoundException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Expand All @@ -67,6 +70,9 @@ protected RemoteMethodNotFoundException(SerializationInfo info, StreamingContext
public new object? DeserializedErrorData => base.DeserializedErrorData;

/// <inheritdoc/>
#if NET8_0_OR_GREATER
[Obsolete]
#endif
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
Expand Down
6 changes: 6 additions & 0 deletions src/StreamJsonRpc/Exceptions/RemoteRpcException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ protected RemoteRpcException(string? message, Exception? innerException)
/// </summary>
/// <param name="info">Serialization info.</param>
/// <param name="context">Streaming context.</param>
#if NET8_0_OR_GREATER
[Obsolete]
#endif
protected RemoteRpcException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Expand Down Expand Up @@ -69,6 +72,9 @@ protected RemoteRpcException(SerializationInfo info, StreamingContext context)
public object? DeserializedErrorData { get; protected set; }

/// <inheritdoc/>
#if NET8_0_OR_GREATER
[Obsolete]
#endif
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
Expand Down
3 changes: 3 additions & 0 deletions src/StreamJsonRpc/Exceptions/RemoteSerializationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public RemoteSerializationException(string? message, object? errorData, object?
/// </summary>
/// <param name="serializationInfo">Serialization info.</param>
/// <param name="streamingContext">Streaming context.</param>
#if NET8_0_OR_GREATER
[Obsolete]
#endif
protected RemoteSerializationException(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext)
: base(serializationInfo, streamingContext)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public RpcArgumentDeserializationException(string message, Exception? innerExcep
/// </summary>
/// <param name="info">Serialization info.</param>
/// <param name="context">Serialization context.</param>
#if NET8_0_OR_GREATER
[Obsolete]
#endif
protected RpcArgumentDeserializationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Expand Down Expand Up @@ -85,6 +88,9 @@ protected RpcArgumentDeserializationException(SerializationInfo info, StreamingC
public Type? DeserializedType { get; private set; }

/// <inheritdoc/>
#if NET8_0_OR_GREATER
[Obsolete]
#endif
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public UnrecognizedJsonRpcMessageException(string? message, Exception? innerExce
/// </summary>
/// <param name="info">Serialization info.</param>
/// <param name="context">Streaming context.</param>
#if NET8_0_OR_GREATER
[Obsolete]
#endif
protected UnrecognizedJsonRpcMessageException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Expand Down
5 changes: 4 additions & 1 deletion src/StreamJsonRpc/JsonMessageFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,10 @@ internal JsonConverterFormatter(JsonSerializer serializer)
this.serializer = serializer;
}

public object Convert(object value, Type type) => ((JToken)value).ToObject(type, this.serializer)!;
#pragma warning disable CS8766 // This method may in fact return null, and no one cares.
public object? Convert(object value, Type type)
#pragma warning restore CS8766
=> ((JToken)value).ToObject(type, this.serializer);

public object Convert(object value, TypeCode typeCode)
{
Expand Down
2 changes: 1 addition & 1 deletion src/StreamJsonRpc/JsonRpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2219,7 +2219,7 @@ private async ValueTask<JsonRpcMessage> DispatchIncomingRequestAsync(JsonRpcRequ

// Be sure to dispose the link to the local method token we created in case it is linked to our long-lived disposal token
// and otherwise cause a memory leak.
#if NETSTANDARD2_1_OR_GREATER
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
await disconnectedRegistration.DisposeAsync().ConfigureAwait(false);
#else
disconnectedRegistration.Dispose();
Expand Down
4 changes: 4 additions & 0 deletions src/StreamJsonRpc/MessageHandlerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ public virtual async Task DisposeAsync()
{
if (!this.disposalTokenSource.IsCancellationRequested)
{
#if NET8_0_OR_GREATER
await this.disposalTokenSource.CancelAsync().ConfigureAwait(false);
#else
this.disposalTokenSource.Cancel();
#endif

// Kick off disposal of reading and/or writing resources based on whether they're active right now or not.
// If they're active, they'll take care of themselves when they finish since we signaled disposal.
Expand Down
7 changes: 5 additions & 2 deletions src/StreamJsonRpc/MessagePackFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ private static void WriteProtocolVersionPropertyAndValue(ref MessagePackWriter w
private static void ReadUnknownProperty(ref MessagePackReader reader, ref Dictionary<string, ReadOnlySequence<byte>>? topLevelProperties, ReadOnlySpan<byte> stringKey)
{
topLevelProperties ??= new Dictionary<string, ReadOnlySequence<byte>>(StringComparer.Ordinal);
#if NETSTANDARD2_1_OR_GREATER
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
string name = Encoding.UTF8.GetString(stringKey);
#else
string name = Encoding.UTF8.GetString(stringKey.ToArray());
Expand Down Expand Up @@ -660,7 +660,10 @@ internal MessagePackFormatterConverter(MessagePackSerializerOptions options)
this.options = options;
}

public object? Convert(object value, Type type) => ((RawMessagePack)value).Deserialize(type, this.options);
#pragma warning disable CS8766 // This method may in fact return null, and no one cares.
public object? Convert(object value, Type type)
#pragma warning restore CS8766
=> ((RawMessagePack)value).Deserialize(type, this.options);

public object Convert(object value, TypeCode typeCode)
{
Expand Down
8 changes: 4 additions & 4 deletions src/StreamJsonRpc/ProxyGeneration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ internal static TypeInfo Get(TypeInfo contractInterface, (TypeInfo Type, int Cod

Label positionalArgsLabel = il.DefineLabel();

ParameterInfo cancellationTokenParameter = methodParameters.FirstOrDefault(p => p.ParameterType == typeof(CancellationToken));
ParameterInfo? cancellationTokenParameter = methodParameters.FirstOrDefault(p => p.ParameterType == typeof(CancellationToken));
int argumentCountExcludingCancellationToken = methodParameters.Length - (cancellationTokenParameter is not null ? 1 : 0);
VerifySupported(cancellationTokenParameter is null || cancellationTokenParameter.Position == methodParameters.Length - 1, Resources.CancellationTokenMustBeLastParameter, method);

Expand Down Expand Up @@ -913,11 +913,11 @@ public GeneratedProxiesByInterfaceKey(TypeInfo baseInterfaceType, IEnumerable<in
public bool Equals(GeneratedProxiesByInterfaceKey other)
{
return this.baseInterfaceType == other.baseInterfaceType &&
!(this.implementedOptionalInterfaces is not null ^ other.implementedOptionalInterfaces is not null) &&
(this.implementedOptionalInterfaces?.SequenceEqual(other.implementedOptionalInterfaces) ?? true);
((this.implementedOptionalInterfaces is null && other.implementedOptionalInterfaces is null) ||
(this.implementedOptionalInterfaces is not null && other.implementedOptionalInterfaces is not null && this.implementedOptionalInterfaces.SequenceEqual(other.implementedOptionalInterfaces)));
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return obj is GeneratedProxiesByInterfaceKey other && this.Equals(other);
}
Expand Down
2 changes: 2 additions & 0 deletions src/StreamJsonRpc/Reflection/ExceptionSerializationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ internal static void Serialize(Exception exception, SerializationInfo info)
{
Type exceptionType = exception.GetType();
EnsureSerializableAttribute(exceptionType);
#pragma warning disable SYSLIB0051 // Type or member is obsolete -- NOT so obsolete without the BinaryFormatter.
exception.GetObjectData(info, Context);
#pragma warning restore SYSLIB0051 // Type or member is obsolete
info.AddValue(AssemblyNameKeyName, exception.GetType().Assembly.FullName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,15 @@ public async ValueTask<object> GetNextValuesAsync(CancellationToken cancellation
}
}

public ValueTask DisposeAsync()
public async ValueTask DisposeAsync()
{
#if NET8_0_OR_GREATER
await this.cancellationTokenSource.CancelAsync().ConfigureAwait(false);
#else
this.cancellationTokenSource.Cancel();
#endif
this.readAheadElements?.Complete();
return this.enumerator.DisposeAsync();
await this.enumerator.DisposeAsync().ConfigureAwait(false);
}

private async Task ReadAheadAsync()
Expand Down
3 changes: 2 additions & 1 deletion src/StreamJsonRpc/Reflection/RpcTargetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,8 @@ private void AddRpcInterfaceToTarget(IReadOnlyDictionary<string, List<MethodSign
// Only add methods that do not have equivalent signatures to what we already have.
foreach (MethodSignature newMethod in item.Value)
{
if (!alreadyExists || !existingList.Any(e => e.Equals(newMethod)))
// Null forgiveness operator in use due to: https://github.com/dotnet/roslyn/issues/73274
if (!alreadyExists || !existingList!.Any(e => e.Equals(newMethod)))
{
var signatureAndTarget = new MethodSignatureAndTarget(newMethod, target, null);
this.TraceLocalMethodAdded(rpcMethodName, signatureAndTarget);
Expand Down
2 changes: 1 addition & 1 deletion src/StreamJsonRpc/Reflection/TrackerHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal static class TrackerHelpers<TInterface>
/// <summary>
/// Dictionary to record the calculation made in <see cref="FindInterfaceImplementedBy(Type)"/> to obtain the <typeparamref name="TInterface"/> type from a given <see cref="Type"/>.
/// </summary>
private static readonly Dictionary<Type, Type> TypeToImplementedInterfaceMap = new Dictionary<Type, Type>();
private static readonly Dictionary<Type, Type?> TypeToImplementedInterfaceMap = new();

/// <summary>
/// Gets the generic type definition for whatever type parameter was given by <typeparamref name="TInterface" />.
Expand Down
2 changes: 1 addition & 1 deletion src/StreamJsonRpc/RequestId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public RequestId(string? id)
public override bool Equals(object? obj) => obj is RequestId other && this.Equals(other);

/// <inheritdoc/>
#if NETSTANDARD2_1_OR_GREATER
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
public override int GetHashCode() => this.Number?.GetHashCode() ?? this.String?.GetHashCode(StringComparison.Ordinal) ?? 0;
#else
public override int GetHashCode() => this.Number?.GetHashCode() ?? this.String?.GetHashCode() ?? 0;
Expand Down
15 changes: 11 additions & 4 deletions src/StreamJsonRpc/StreamJsonRpc.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net8.0</TargetFrameworks>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

<Description>A cross-platform .NETStandard library that implements the JSON-RPC wire protocol and can use System.IO.Stream, System.IO.Pipelines or WebSocket so you can use it with any transport.</Description>
<PackageTags>visualstudio stream json rpc jsonrpc</PackageTags>
<!-- We use the ISerializable APIs *without* the BinaryFormatter. Not as obsolete as the .NET SDK would have us believe. -->
<NoWarn>$(NoWarn);SYSLIB0050</NoWarn>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Update="Resources.resx" />
Expand All @@ -16,16 +17,22 @@
<PackageReference Include="MessagePack" />
<PackageReference Include="MessagePackAnalyzer" PrivateAssets="all" />
<PackageReference Include="Microsoft.VisualStudio.Threading" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" PrivateAssets="compile" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
<PackageReference Include="Nerdbank.Streams" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" PrivateAssets="all" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'== 'netstandard2.0'">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" PrivateAssets="compile"/>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'== 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="System.Collections.Immutable" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" />
<PackageReference Include="System.IO.Pipelines" />
<PackageReference Include="System.Text.Json" />
<PackageReference Include="System.Threading.Tasks.Dataflow" PrivateAssets="compile" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'== 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == 'net6.0'">
<PackageReference Include="System.Text.Json" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="$(TargetFramework)\PublicAPI.Shipped.txt" />
<AdditionalFiles Include="$(TargetFramework)\PublicAPI.Unshipped.txt" />
Expand Down
9 changes: 4 additions & 5 deletions src/StreamJsonRpc/SystemTextJsonFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,16 +1104,15 @@ internal JsonConverterFormatter(JsonSerializerOptions serializerOptions)
this.serializerOptions = serializerOptions;
}

#pragma warning disable CS8766 // This method may in fact return null, and no one cares.
public object? Convert(object value, Type type)
#pragma warning restore CS8766
{
var jsonValue = (JsonNode?)value;
if (jsonValue is null)
{
return null;
}
var jsonValue = (JsonNode)value;

if (type == typeof(System.Collections.IDictionary))
{
// In this world, we may in fact be returning a null value based on a non-null value.
return DeserializePrimitive(jsonValue);
}

Expand Down
6 changes: 3 additions & 3 deletions src/StreamJsonRpc/WebSocketMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ void IJsonRpcMessageBufferManager.DeserializationComplete(JsonRpcMessage message
/// <inheritdoc />
protected override async ValueTask<JsonRpcMessage?> ReadCoreAsync(CancellationToken cancellationToken)
{
#if NETSTANDARD2_1_OR_GREATER
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
ValueWebSocketReceiveResult result;
#else
WebSocketReceiveResult result;
#endif
do
{
#if NETSTANDARD2_1_OR_GREATER
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
Memory<byte> memory = this.contentSequenceBuilder.GetMemory(this.sizeHint);
result = await this.WebSocket.ReceiveAsync(memory, cancellationToken).ConfigureAwait(false);
this.contentSequenceBuilder.Advance(result.Count);
Expand Down Expand Up @@ -155,7 +155,7 @@ protected override async ValueTask WriteCoreAsync(JsonRpcMessage content, Cancel
foreach (ReadOnlyMemory<byte> memory in contentSequence)
{
bool endOfMessage = bytesCopied + memory.Length == contentSequence.Length;
#if NETSTANDARD2_1_OR_GREATER
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
await this.WebSocket.SendAsync(memory, messageType, endOfMessage, cancellationToken).ConfigureAwait(false);
#else
if (MemoryMarshal.TryGetArray(memory, out ArraySegment<byte> segment))
Expand Down
Loading

0 comments on commit e269ac6

Please sign in to comment.