Skip to content

Commit bcc52fd

Browse files
netstandard 2.1 support for Orleans.Serialization (#8222)
* netstandard2.1 compatible serialization * use build property for package version * fix merge errors and handle additional upstream changes * Update src/Orleans.Serialization/Codecs/GuidCodec.cs Co-authored-by: Reuben Bond <[email protected]> * add netstandard2.1 (via netcoreapp3.1) test coverage for serialization * install other .net versions in ci * don't pin segment array to prevent possible leaking in a simple manner * Fix issues causing test failures (#2) xref: #8222 * Create pre net7 version of NumericsWideningAndNarrowingTests Co-authored-by: Reuben Bond <[email protected]>
1 parent 1fca153 commit bcc52fd

34 files changed

+735
-73
lines changed

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ jobs:
2121
- uses: actions/checkout@v2
2222
- name: Setup .NET
2323
uses: actions/setup-dotnet@v1
24+
with:
25+
dotnet-version: |
26+
3.1.x
27+
7.0.x
2428
- name: Build
2529
run: dotnet build
2630
- uses: actions/upload-artifact@v3
@@ -49,6 +53,10 @@ jobs:
4953
- uses: actions/checkout@v2
5054
- name: Setup .NET
5155
uses: actions/setup-dotnet@v2
56+
with:
57+
dotnet-version: |
58+
3.1.x
59+
7.0.x
5260
- name: Test
5361
run: dotnet test --filter "Category=${{ matrix.provider }}&(Category=BVT|Category=SlowBVT|Category=Functional)" --blame-hang-timeout 10m --logger "trx" -- -parallel none -noshadow
5462
env:
@@ -85,6 +93,10 @@ jobs:
8593
- uses: actions/checkout@v2
8694
- name: Setup .NET
8795
uses: actions/setup-dotnet@v2
96+
with:
97+
dotnet-version: |
98+
3.1.x
99+
7.0.x
88100
- name: Test
89101
run: dotnet test --filter "Category=${{ matrix.provider }}&(Category=BVT|Category=SlowBVT|Category=Functional)" --blame-hang-timeout 10m --logger "trx" -- -parallel none -noshadow
90102
env:
@@ -117,6 +129,10 @@ jobs:
117129
- uses: actions/checkout@v2
118130
- name: Setup .NET
119131
uses: actions/setup-dotnet@v1
132+
with:
133+
dotnet-version: |
134+
3.1.x
135+
7.0.x
120136
- name: Test
121137
run: dotnet test --filter "Category=${{ matrix.provider }}&(Category=BVT|Category=SlowBVT|Category=Functional)" --blame-hang-timeout 10m --logger "trx" -- -parallel none -noshadow
122138
env:
@@ -153,6 +169,10 @@ jobs:
153169
- uses: actions/checkout@v2
154170
- name: Setup .NET
155171
uses: actions/setup-dotnet@v1
172+
with:
173+
dotnet-version: |
174+
3.1.x
175+
7.0.x
156176
- name: Test
157177
run: dotnet test --filter "Category=${{ matrix.provider }}&(Category=BVT|Category=SlowBVT|Category=Functional)" --blame-hang-timeout 10m --logger "trx" -- -parallel none -noshadow
158178
env:
@@ -187,6 +207,10 @@ jobs:
187207
- uses: actions/checkout@v2
188208
- name: Setup .NET
189209
uses: actions/setup-dotnet@v1
210+
with:
211+
dotnet-version: |
212+
3.1.x
213+
7.0.x
190214
- name: Test
191215
run: dotnet test --filter "Category=${{ matrix.provider }}&Category=${{ matrix.suite }}" --framework ${{ matrix.framework }} --blame-hang-timeout 10m --logger "trx" -- -parallel none -noshadow
192216
env:
@@ -220,6 +244,10 @@ jobs:
220244
- uses: actions/checkout@v2
221245
- name: Setup .NET
222246
uses: actions/setup-dotnet@v1
247+
with:
248+
dotnet-version: |
249+
3.1.x
250+
7.0.x
223251
- name: Test
224252
run: dotnet test --filter "Category=${{ matrix.provider }}&(Category=BVT|Category=SlowBVT|Category=Functional)" --blame-hang-timeout 10m --logger "trx" -- -parallel none -noshadow
225253
env:
@@ -253,6 +281,10 @@ jobs:
253281
- uses: actions/checkout@v2
254282
- name: Setup .NET
255283
uses: actions/setup-dotnet@v1
284+
with:
285+
dotnet-version: |
286+
3.1.x
287+
7.0.x
256288
- name: Test
257289
run: dotnet test --filter "Category=${{ matrix.provider }}&(Category=BVT|Category=SlowBVT|Category=Functional)" --blame-hang-timeout 10m --logger "trx" -- -parallel none -noshadow
258290
env:
@@ -287,6 +319,10 @@ jobs:
287319
- uses: actions/checkout@v2
288320
- name: Setup .NET
289321
uses: actions/setup-dotnet@v1
322+
with:
323+
dotnet-version: |
324+
3.1.x
325+
7.0.x
290326
- name: Test
291327
run: dotnet test --filter "Category=${{ matrix.provider }}&(Category=BVT|Category=SlowBVT|Category=Functional)" --blame-hang-timeout 10m --logger "trx" -- -parallel none -noshadow
292328
env:

Directory.Packages.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<PackageVersion Include="System.IO.Pipelines" Version="7.0.0" />
1919
<PackageVersion Include="System.Memory.Data" Version="7.0.0" />
2020
<PackageVersion Include="System.Net.NameResolution" Version="4.3.0" />
21+
<PackageVersion Include="System.Collections.Immutable" Version="7.0.0" />
2122
<!-- Microsoft packages -->
2223
<PackageVersion Include="Microsoft.Build" Version="17.3.2" />
2324
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
@@ -27,6 +28,7 @@
2728
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(MicrosoftCodeAnalysisVersion)" />
2829
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="$(MicrosoftCodeAnalysisVersion)" />
2930
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" />
31+
<PackageVersion Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.6" />
3032
<PackageVersion Include="Microsoft.AspNetCore.Connections.Abstractions" Version="7.0.0" />
3133
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="$(MicrosoftExtensionsConfigurationVersion)" />
3234
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="$(MicrosoftExtensionsConfigurationVersion)" />

src/Orleans.CodeGenerator/LibraryTypes.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Concurrent;
3+
using System.Collections.Generic;
34
using System.Collections.Immutable;
45
using System.Linq;
56
using Microsoft.CodeAnalysis;
@@ -66,17 +67,17 @@ public static LibraryTypes FromCompilation(Compilation compilation, CodeGenerato
6667
Task_1 = Type("System.Threading.Tasks.Task`1"),
6768
Type = Type("System.Type"),
6869
Uri = Type("System.Uri"),
69-
Int128 = Type("System.Int128"),
70-
UInt128 = Type("System.UInt128"),
71-
Half = Type("System.Half"),
72-
DateOnly = Type("System.DateOnly"),
70+
Int128 = TypeOrDefault("System.Int128"),
71+
UInt128 = TypeOrDefault("System.UInt128"),
72+
Half = TypeOrDefault("System.Half"),
73+
DateOnly = TypeOrDefault("System.DateOnly"),
7374
DateTimeOffset = Type("System.DateTimeOffset"),
7475
BitVector32 = Type("System.Collections.Specialized.BitVector32"),
7576
Guid = Type("System.Guid"),
7677
CompareInfo = Type("System.Globalization.CompareInfo"),
7778
CultureInfo = Type("System.Globalization.CultureInfo"),
7879
Version = Type("System.Version"),
79-
TimeOnly = Type("System.TimeOnly"),
80+
TimeOnly = TypeOrDefault("System.TimeOnly"),
8081
ICodecProvider = Type("Orleans.Serialization.Serializers.ICodecProvider"),
8182
ValueSerializer = Type("Orleans.Serialization.Serializers.IValueSerializer`1"),
8283
ValueTask = Type("System.Threading.Tasks.ValueTask"),
@@ -86,7 +87,7 @@ public static LibraryTypes FromCompilation(Compilation compilation, CodeGenerato
8687
Writer = Type("Orleans.Serialization.Buffers.Writer`1"),
8788
FSharpSourceConstructFlagsOrDefault = TypeOrDefault("Microsoft.FSharp.Core.SourceConstructFlags"),
8889
FSharpCompilationMappingAttributeOrDefault = TypeOrDefault("Microsoft.FSharp.Core.CompilationMappingAttribute"),
89-
StaticCodecs = new WellKnownCodecDescription[]
90+
StaticCodecs = new List<WellKnownCodecDescription>
9091
{
9192
new(compilation.GetSpecialType(SpecialType.System_Object), Type("Orleans.Serialization.Codecs.ObjectCodec")),
9293
new(compilation.GetSpecialType(SpecialType.System_Boolean), Type("Orleans.Serialization.Codecs.BoolCodec")),
@@ -107,19 +108,19 @@ public static LibraryTypes FromCompilation(Compilation compilation, CodeGenerato
107108
new(compilation.GetSpecialType(SpecialType.System_DateTime), Type("Orleans.Serialization.Codecs.DateTimeCodec")),
108109
new(Type("System.TimeSpan"), Type("Orleans.Serialization.Codecs.TimeSpanCodec")),
109110
new(Type("System.DateTimeOffset"), Type("Orleans.Serialization.Codecs.DateTimeOffsetCodec")),
110-
new(Type("System.DateOnly"), Type("Orleans.Serialization.Codecs.DateOnlyCodec")),
111-
new(Type("System.TimeOnly"), Type("Orleans.Serialization.Codecs.TimeOnlyCodec")),
111+
new(TypeOrDefault("System.DateOnly"), TypeOrDefault("Orleans.Serialization.Codecs.DateOnlyCodec")),
112+
new(TypeOrDefault("System.TimeOnly"), TypeOrDefault("Orleans.Serialization.Codecs.TimeOnlyCodec")),
112113
new(Type("System.Guid"), Type("Orleans.Serialization.Codecs.GuidCodec")),
113114
new(Type("System.Type"), Type("Orleans.Serialization.Codecs.TypeSerializerCodec")),
114115
new(Type("System.ReadOnlyMemory`1").Construct(compilation.GetSpecialType(SpecialType.System_Byte)), Type("Orleans.Serialization.Codecs.ReadOnlyMemoryOfByteCodec")),
115116
new(Type("System.Memory`1").Construct(compilation.GetSpecialType(SpecialType.System_Byte)), Type("Orleans.Serialization.Codecs.MemoryOfByteCodec")),
116117
new(Type("System.Net.IPAddress"), Type("Orleans.Serialization.Codecs.IPAddressCodec")),
117118
new(Type("System.Net.IPEndPoint"), Type("Orleans.Serialization.Codecs.IPEndPointCodec")),
118-
new(Type("System.UInt128"), Type("Orleans.Serialization.Codecs.UInt128Codec")),
119-
new(Type("System.Int128"), Type("Orleans.Serialization.Codecs.Int128Codec")),
120-
new(Type("System.Half"), Type("Orleans.Serialization.Codecs.HalfCodec")),
119+
new(TypeOrDefault("System.UInt128"), TypeOrDefault("Orleans.Serialization.Codecs.UInt128Codec")),
120+
new(TypeOrDefault("System.Int128"), TypeOrDefault("Orleans.Serialization.Codecs.Int128Codec")),
121+
new(TypeOrDefault("System.Half"), TypeOrDefault("Orleans.Serialization.Codecs.HalfCodec")),
121122
new(Type("System.Uri"), Type("Orleans.Serialization.Codecs.UriCodec")),
122-
},
123+
}.Where(desc => desc.UnderlyingType is {} && desc.CodecType is {}).ToArray(),
123124
WellKnownCodecs = new WellKnownCodecDescription[]
124125
{
125126
new(Type("System.Exception"), Type("Orleans.Serialization.ExceptionCodec")),
@@ -266,7 +267,7 @@ INamedTypeSymbol TypeOrDefault(string metadataName)
266267
private INamedTypeSymbol UInt128;
267268
private INamedTypeSymbol Half;
268269
private INamedTypeSymbol[] _regularShallowCopyableTypes;
269-
private INamedTypeSymbol[] RegularShallowCopyableType => _regularShallowCopyableTypes ??= new[]
270+
private INamedTypeSymbol[] RegularShallowCopyableType => _regularShallowCopyableTypes ??= new List<INamedTypeSymbol>
270271
{
271272
TimeSpan,
272273
DateOnly,
@@ -285,7 +286,7 @@ INamedTypeSymbol TypeOrDefault(string metadataName)
285286
UInt128,
286287
Int128,
287288
Half
288-
};
289+
}.Where(t => t is {}).ToArray();
289290

290291
public INamedTypeSymbol[] ImmutableAttributes { get; private set; }
291292
public INamedTypeSymbol Exception { get; private set; }

src/Orleans.Serialization.FSharp/Orleans.Serialization.FSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<PackageId>Microsoft.Orleans.Serialization.FSharp</PackageId>
5-
<TargetFrameworks>$(DefaultTargetFrameworks)</TargetFrameworks>
5+
<TargetFrameworks>$(DefaultTargetFrameworks);netstandard2.1</TargetFrameworks>
66
<PackageDescription>F# core type support for Orleans.Serialization</PackageDescription>
77
<OrleansBuildTimeCodeGen>true</OrleansBuildTimeCodeGen>
88
<IsOrleansFrameworkPart>false</IsOrleansFrameworkPart>

src/Orleans.Serialization.NewtonsoftJson/Orleans.Serialization.NewtonsoftJson.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<PackageId>Microsoft.Orleans.Serialization.NewtonsoftJson</PackageId>
5-
<TargetFrameworks>$(DefaultTargetFrameworks)</TargetFrameworks>
5+
<TargetFrameworks>$(DefaultTargetFrameworks);netstandard2.1</TargetFrameworks>
66
<PackageDescription>Newtonsoft.Json integration for Orleans.Serialization</PackageDescription>
77
<OrleansBuildTimeCodeGen>true</OrleansBuildTimeCodeGen>
88
<IsOrleansFrameworkPart>false</IsOrleansFrameworkPart>

src/Orleans.Serialization.SystemTextJson/Orleans.Serialization.SystemTextJson.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<PackageId>Microsoft.Orleans.Serialization.SystemTextJson</PackageId>
5-
<TargetFrameworks>$(DefaultTargetFrameworks)</TargetFrameworks>
5+
<TargetFrameworks>$(DefaultTargetFrameworks);netstandard2.1</TargetFrameworks>
66
<PackageDescription>System.Text.Json integration for Orleans.Serialization</PackageDescription>
77
<OrleansBuildTimeCodeGen>true</OrleansBuildTimeCodeGen>
88
<IsOrleansFrameworkPart>false</IsOrleansFrameworkPart>

src/Orleans.Serialization.TestKit/CopierTester.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ public abstract class CopierTester<TValue, TCopier> where TCopier : class, IDeep
1818

1919
protected CopierTester(ITestOutputHelper output)
2020
{
21+
#if NET6_0_OR_GREATER
2122
var seed = Random.Shared.Next();
23+
#else
24+
var seed = new Random().Next();
25+
#endif
2226
output.WriteLine($"Random seed: {seed}");
2327
Random = new(seed);
2428
var services = new ServiceCollection();
@@ -51,7 +55,7 @@ protected virtual void Configure(ISerializerBuilder builder)
5155
protected virtual bool Equals(TValue left, TValue right) => EqualityComparer<TValue>.Default.Equals(left, right);
5256

5357
protected virtual Action<Action<TValue>> ValueProvider { get; }
54-
58+
5559
[Fact]
5660
public void CopiedValuesAreEqual()
5761
{

src/Orleans.Serialization.TestKit/FieldCodecTester.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ public abstract class FieldCodecTester<TValue, TCodec> : IDisposable where TCode
2626

2727
protected FieldCodecTester(ITestOutputHelper output)
2828
{
29+
#if NET6_0_OR_GREATER
2930
var seed = Random.Shared.Next();
31+
#else
32+
var seed = new Random().Next();
33+
#endif
3034
output.WriteLine($"Random seed: {seed}");
3135
Random = new(seed);
3236
var services = new ServiceCollection();
@@ -121,7 +125,7 @@ public void CorrectlyAdvancesReferenceCounterStream()
121125
public void CorrectlyAdvancesReferenceCounter()
122126
{
123127
var pipe = new Pipe();
124-
using var writerSession = _sessionPool.GetSession();
128+
using var writerSession = _sessionPool.GetSession();
125129
var writer = Writer.Create(pipe.Writer, writerSession);
126130
var writerCodec = CreateCodec();
127131
var beforeReference = writer.Session.ReferencedObjects.CurrentReferenceId;
@@ -139,7 +143,7 @@ public void CorrectlyAdvancesReferenceCounter()
139143
pipe.Writer.Complete();
140144

141145
_ = pipe.Reader.TryRead(out var readResult);
142-
using var readerSession = _sessionPool.GetSession();
146+
using var readerSession = _sessionPool.GetSession();
143147
var reader = Reader.Create(readResult.Buffer, readerSession);
144148

145149
var previousPos = reader.Position;

src/Orleans.Serialization.TestKit/Orleans.Serialization.TestKit.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<PackageId>Microsoft.Orleans.Serialization.TestKit</PackageId>
5-
<TargetFrameworks>$(DefaultTargetFrameworks)</TargetFrameworks>
5+
<TargetFrameworks>$(DefaultTargetFrameworks);netstandard2.1</TargetFrameworks>
66
<PackageDescription>Test kit for projects using Orleans.Serialization</PackageDescription>
77
<IsOrleansFrameworkPart>false</IsOrleansFrameworkPart>
88
</PropertyGroup>

src/Orleans.Serialization/Activators/DefaultActivator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private static Func<T> Init()
2121
var il = method.GetILGenerator();
2222
il.Emit(OpCodes.Newobj, ctor);
2323
il.Emit(OpCodes.Ret);
24-
return method.CreateDelegate<Func<T>>();
24+
return (Func<T>)method.CreateDelegate(typeof(Func<T>));
2525
}
2626

2727
public T Create() => _constructor is { } ctor ? ctor() : Unsafe.As<T>(FormatterServices.GetUninitializedObject(_type));

0 commit comments

Comments
 (0)