Skip to content

Commit c3f903f

Browse files
thaystgThays Grazia
andauthored
Avoid trying to use _hotReloadAgent variable before it is initialized (#46916)
* trying to fix 45190 * change initialization order * keeping old \n * keeping the comment * keeping the comment * addressing @tmat comment --------- Co-authored-by: Thays Grazia <[email protected]>
1 parent 572993c commit c3f903f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/Components/WebAssembly/WebAssembly/src/HotReload/WebAssemblyHotReload.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ public static class WebAssemblyHotReload
2626

2727
internal static async Task InitializeAsync()
2828
{
29-
// Analyzer has a bug where it doesn't handle ConditionalAttribute: https://github.com/dotnet/roslyn/issues/63464
30-
#pragma warning disable IDE0200 // Remove unnecessary lambda expression
31-
_hotReloadAgent = new HotReloadAgent(m => Debug.WriteLine(m));
32-
#pragma warning restore IDE0200 // Remove unnecessary lambda expression
33-
3429
if (Environment.GetEnvironmentVariable("__ASPNETCORE_BROWSER_TOOLS") == "true")
3530
{
3631
// Attempt to read previously applied hot reload deltas if the ASP.NET Core browser tools are available (indicated by the presence of the Environment variable).
@@ -50,14 +45,19 @@ internal static async Task InitializeAsync()
5045
[JSInvokable(nameof(ApplyHotReloadDelta))]
5146
public static void ApplyHotReloadDelta(string moduleIdString, byte[] metadataDelta, byte[] ilDelta, byte[] pdbBytes)
5247
{
48+
// Analyzer has a bug where it doesn't handle ConditionalAttribute: https://github.com/dotnet/roslyn/issues/63464
49+
#pragma warning disable IDE0200 // Remove unnecessary lambda expression
50+
Interlocked.CompareExchange(ref _hotReloadAgent, new HotReloadAgent(m => Debug.WriteLine(m)), null);
51+
#pragma warning restore IDE0200 // Remove unnecessary lambda expression
52+
5353
var moduleId = Guid.Parse(moduleIdString, CultureInfo.InvariantCulture);
5454

5555
_updateDeltas[0].ModuleId = moduleId;
5656
_updateDeltas[0].MetadataDelta = metadataDelta;
5757
_updateDeltas[0].ILDelta = ilDelta;
5858
_updateDeltas[0].PdbBytes = pdbBytes;
5959

60-
_hotReloadAgent!.ApplyDeltas(_updateDeltas);
60+
_hotReloadAgent.ApplyDeltas(_updateDeltas);
6161
}
6262

6363
/// <summary>

0 commit comments

Comments
 (0)