Skip to content

Commit 06e8f47

Browse files
authored
Remove AOT conditional exclusions for SignalR and delete deprecated methods (#403)
* Remove AOT conditional exclusions for SignalR and delete deprecated methods - Remove #define AOT constant and SignalR Compile Remove entries from csproj - Remove Condition on SignalR.Client PackageReference for AOT builds - Remove #if !AOT blocks in GeneralUpdateBootstrap.cs (HubDownloadSource + LaunchSilentAsync) - Delete deprecated abstract/override methods (ExecuteStrategy, ExecuteStrategyAsync, StrategyFactory) Closes #402 * Fix HubDownloadSource AOT support and Hub start silent failure - Add PacketDTO to HttpParameterJsonContext for source-generated AOT deserialization - Replace reflection-based Deserialize<PacketDTO> with source-gen version in HubDownloadSource - Remove try/catch in UpgradeHubService.StartAsync so hub connection failures propagate
1 parent 3a18f27 commit 06e8f47

6 files changed

Lines changed: 13 additions & 38 deletions

File tree

src/c#/GeneralUpdate.Core/Bootstrap/GeneralUpdateBootstrap.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ private async Task<GeneralUpdateBootstrap> LaunchWithStrategy(IStrategy roleStra
9696
// Resolve DownloadSource from extension registry (Hub, custom, etc.)
9797
var resolvedSource = ResolveExtension<Download.Abstractions.IDownloadSource>();
9898

99-
// Inject SignalR Hub download source if configured (not available in AOT)
100-
#if !AOT
99+
// Inject SignalR Hub download source if configured
101100
if (resolvedSource == null)
102101
{
103102
var hubConfig = GetOption(UpdateOptions.Hub);
@@ -110,7 +109,6 @@ private async Task<GeneralUpdateBootstrap> LaunchWithStrategy(IStrategy roleStra
110109
GeneralTracer.Info("GeneralUpdateBootstrap: HubDownloadSource started from HubConfig.");
111110
}
112111
}
113-
#endif
114112
clientStrat.DownloadSource = resolvedSource;
115113
if (_updatePrecheck != null)
116114
clientStrat.UseUpdatePrecheck(_updatePrecheck);
@@ -316,11 +314,9 @@ private void ApplyRuntimeOptions()
316314
/// Silent update mode — starts a background poll loop and returns immediately.
317315
/// The orchestrator checks for updates periodically and prepares them.
318316
/// When the host process exits, the prepared update is applied.
319-
/// Not available in AOT builds (SignalR dependency).
320317
/// </summary>
321318
private async Task LaunchSilentAsync()
322319
{
323-
#if !AOT
324320
GeneralTracer.Info("GeneralUpdateBootstrap: starting silent update mode.");
325321

326322
var pollMinutes = GetOption(UpdateOptions.SilentPollIntervalMinutes);
@@ -341,10 +337,6 @@ private async Task LaunchSilentAsync()
341337

342338
await orchestrator.StartAsync().ConfigureAwait(false);
343339
GeneralTracer.Info("GeneralUpdateBootstrap: silent update mode started, returning to caller.");
344-
#else
345-
GeneralTracer.Warn("GeneralUpdateBootstrap: silent update not available in AOT builds.");
346-
await Task.CompletedTask;
347-
#endif
348340
}
349341

350342
private void InitBlackList()
@@ -396,12 +388,6 @@ private static bool IsOssUpgrade(string clientVersion, string serverVersion)
396388
// Strategy & Events
397389
// ════════════════════════════════════════════════════════════════
398390

399-
protected override GeneralUpdateBootstrap StrategyFactory()
400-
=> throw new NotImplementedException("Role strategies handle this.");
401-
402-
protected override Task ExecuteStrategyAsync() => throw new NotImplementedException();
403-
protected override void ExecuteStrategy() => throw new NotImplementedException();
404-
405391
private GeneralUpdateBootstrap AddListener<TArgs>(Action<object, TArgs> action) where TArgs : EventArgs
406392
{
407393
if (action is null) throw new ArgumentNullException(nameof(action));

src/c#/GeneralUpdate.Core/Configuration/AbstractBootstrap.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ protected internal AbstractBootstrap()
2626
}
2727

2828
public abstract Task<TBootstrap> LaunchAsync();
29-
protected abstract void ExecuteStrategy();
30-
protected abstract Task ExecuteStrategyAsync();
31-
protected abstract TBootstrap StrategyFactory();
3229

3330
public TBootstrap Option<T>(UpdateOption<T> option, T value)
3431
{

src/c#/GeneralUpdate.Core/Download/Sources/HubDownloadSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private void OnReceiveMessage(string json)
5151
{
5252
try
5353
{
54-
var packet = System.Text.Json.JsonSerializer.Deserialize<PacketDTO>(json);
54+
var packet = System.Text.Json.JsonSerializer.Deserialize(json, HttpParameterJsonContext.Default.PacketDTO);
5555
if (packet != null)
5656
{
5757
var asset = DownloadPlanBuilder.MapToAsset(packet);

src/c#/GeneralUpdate.Core/GeneralUpdate.Core.csproj

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,29 @@
1414
<TargetFrameworks>netstandard2.0;net8.0;net10.0</TargetFrameworks>
1515
<IsAotCompatible Condition="'$(TargetFramework)' != 'netstandard2.0'">true</IsAotCompatible>
1616
<EnableTrimAnalyzer Condition="'$(TargetFramework)' != 'netstandard2.0'">true</EnableTrimAnalyzer>
17-
<!-- AOT constant for conditional compilation (exclude SignalR, etc.) -->
18-
<DefineConstants Condition="'$(PublishAot)' == 'true'">$(DefineConstants);AOT</DefineConstants>
17+
1918
</PropertyGroup>
2019

2120
<!-- Compatibility packages for netstandard2.0 -->
2221
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
2322
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="10.0.1" />
2423
<PackageReference Include="System.Collections.Immutable" Version="10.0.1" />
2524
<PackageReference Include="System.Text.Json" Version="10.0.1" />
26-
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="10.0.1" Condition="'$(PublishAot)' != 'true'" />
25+
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="10.0.1" />
2726
</ItemGroup>
2827

2928
<!-- Packages only needed for net8.0 (built-in in net10.0) -->
3029
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
31-
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.0" Condition="'$(PublishAot)' != 'true'" />
30+
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.0" />
3231
</ItemGroup>
3332

3433
<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
35-
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="10.0.1" Condition="'$(PublishAot)' != 'true'" />
34+
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="10.0.1" />
3635
</ItemGroup>
3736

3837
<ItemGroup>
3938
<!-- IsExternalInit is built-in for net8.0+ (C# 9 records) -->
4039
<Compile Remove="Configuration\IsExternalInit.cs" Condition="'$(TargetFramework)' != 'netstandard2.0'" />
41-
<!-- SignalR Hub code excluded in AOT builds -->
42-
<Compile Remove="Hubs\*.cs" Condition="'$(PublishAot)' == 'true'" />
43-
<Compile Remove="Download\Sources\HubDownloadSource.cs" Condition="'$(PublishAot)' == 'true'" />
44-
<Compile Remove="Silent\SilentPollOrchestrator.cs" Condition="'$(PublishAot)' == 'true'" />
40+
4541
</ItemGroup>
4642
</Project>

src/c#/GeneralUpdate.Core/Hubs/UpgradeHubService.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,9 @@ public void AddListenerClosed(Func<Exception?, Task> closeCallback)
5555

5656
public async Task StartAsync()
5757
{
58-
try
59-
{
60-
GeneralTracer.Info($"UpgradeHubService.StartAsync: connecting to SignalR hub. State={_connection?.State}");
61-
await _connection!.StartAsync();
62-
GeneralTracer.Info($"UpgradeHubService.StartAsync: SignalR hub connection established. State={_connection?.State}");
63-
}
64-
catch (Exception e)
65-
{
66-
GeneralTracer.Error("The StartAsync method in the UpgradeHubService class throws an exception." , e);
67-
}
58+
GeneralTracer.Info($"UpgradeHubService.StartAsync: connecting to SignalR hub. State={_connection?.State}");
59+
await _connection!.StartAsync();
60+
GeneralTracer.Info($"UpgradeHubService.StartAsync: SignalR hub connection established. State={_connection?.State}");
6861
}
6962

7063
public async Task StopAsync()

src/c#/GeneralUpdate.Core/JsonContext/HttpParameterJsonContext.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using System.Text.Json.Serialization;
3+
using GeneralUpdate.Core.Download.Abstractions;
34

45
namespace GeneralUpdate.Core.JsonContext;
56

@@ -9,4 +10,6 @@ namespace GeneralUpdate.Core.JsonContext;
910
[JsonSerializable(typeof(int?))]
1011
[JsonSerializable(typeof(string))]
1112
[JsonSerializable(typeof(Dictionary<string, object>))]
13+
[JsonSerializable(typeof(PacketDTO))]
14+
[JsonSerializable(typeof(List<PacketDTO>))]
1215
public partial class HttpParameterJsonContext: JsonSerializerContext;

0 commit comments

Comments
 (0)