Skip to content

Commit a2b503a

Browse files
committed
fix(serialization): correct hot reload refresh guards
1 parent a0c484a commit a2b503a

5 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎src/Orleans.Serialization/Hosting/HotReloadMetadataUpdateHandler.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if NET
1+
#if NET6_0_OR_GREATER
22
using System;
33
using System.Collections.Concurrent;
44
using System.Collections.Generic;

‎src/Orleans.Serialization/Hosting/SerializationHotReloadRefresher.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if NET
1+
#if NET6_0_OR_GREATER
22
using System;
33
using System.Collections.Generic;
44
using System.Reflection;

‎src/Orleans.Serialization/Hosting/ServiceCollectionExtensions.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static IServiceCollection AddSerializer(this IServiceCollection services,
8787
services.TryAddSingleton<DeepCopier>();
8888
services.TryAddSingleton(typeof(DeepCopier<>));
8989

90-
#if NET
90+
#if NET6_0_OR_GREATER
9191
if (System.Reflection.Metadata.MetadataUpdater.IsSupported)
9292
{
9393
services.TryAddSingleton<Hosting.SerializationHotReloadRefresher>();

‎src/Orleans.Serialization/Serializers/CodecProvider.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private void Initialize()
9090

9191
_initialized = true;
9292

93-
#if NET
93+
#if NET6_0_OR_GREATER
9494
if (System.Reflection.Metadata.MetadataUpdater.IsSupported)
9595
{
9696
// Construct the hot reload refresher (if registered) so it subscribes before the first update.

‎test/Orleans.Serialization.UnitTests/HotReloadRefreshTests.cs‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,24 @@ public void RefreshRecoversDeniedTypeNames()
8080
Assert.ThrowsAny<Exception>(() => typeConverter.Parse(formatted));
8181
Assert.ThrowsAny<Exception>(() => typeConverter.Parse(formatted));
8282

83+
_scenarioFilter.AllowScenarioTypes();
8384
Refresh();
8485

8586
Assert.Equal(typeof(HotReloadScenario.HotReloadAddedType), typeConverter.Parse(formatted));
8687
}
8788

8889
private sealed class ScenarioTypeNameFilter : Orleans.Serialization.ITypeNameFilter
8990
{
91+
private bool _denyScenarioTypes = true;
92+
93+
public void AllowScenarioTypes() => _denyScenarioTypes = false;
94+
9095
public bool? IsTypeNameAllowed(string typeName, string assemblyName)
91-
=> typeName is not null && typeName.Contains(ScenarioNamespaceFragment, StringComparison.Ordinal) ? false : null;
96+
=> _denyScenarioTypes
97+
&& typeName is not null
98+
&& typeName.Contains(ScenarioNamespaceFragment, StringComparison.Ordinal)
99+
? false
100+
: null;
92101
}
93102

94103
[Fact]

0 commit comments

Comments
 (0)