Skip to content

Commit c84315e

Browse files
committed
async dll load
1 parent b0d073c commit c84315e

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

LearnJsonEverything/LearnJsonEverything.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
7-
<NoWarn>NU1701</NoWarn>
7+
<NoWarn>NU1701;BL0007</NoWarn>
88
<LangVersion>latest</LangVersion>
99
<WasmEnableWebcil>false</WasmEnableWebcil>
1010
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>

LearnJsonEverything/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
var host = builder.Build();
1616
_ = host.Services.GetService<HttpClient>();
1717

18-
_ = await CompilationHelpers.LoadAssemblyReferences(host.Services.GetService<HttpClient>()!);
18+
_ = CompilationHelpers.LoadAssemblyReferences(host.Services.GetService<HttpClient>()!);
1919

2020
await host.RunAsync();

LearnJsonEverything/Services/CompilationHelpers.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace LearnJsonEverything.Services;
88
public static class CompilationHelpers
99
{
1010
private static MetadataReference[]? _references;
11+
private static bool _isLoading;
1112

1213
private static readonly string[] EnsuredAssemblies =
1314
[
@@ -18,10 +19,13 @@ public static class CompilationHelpers
1819
"Yaml2JsonNode",
1920
];
2021

21-
public static async Task<MetadataReference[]> LoadAssemblyReferences(HttpClient client)
22+
public static async Task<MetadataReference[]?> LoadAssemblyReferences(HttpClient client)
2223
{
2324
if (_references is null)
2425
{
26+
if (_isLoading) return null;
27+
_isLoading = true;
28+
2529
var refs = AppDomain.CurrentDomain.GetAssemblies();
2630
var names = refs
2731
.Where(x => !x.IsDynamic)
@@ -51,6 +55,7 @@ public static async Task<MetadataReference[]> LoadAssemblyReferences(HttpClient
5155
}
5256

5357
_references = references;
58+
_isLoading = false;
5459
}
5560

5661
return _references;
@@ -59,7 +64,7 @@ public static async Task<MetadataReference[]> LoadAssemblyReferences(HttpClient
5964
public static (ILessonRunner<T>?, string[]) GetRunner<T>(LessonData lesson, string userCode)
6065
{
6166
if (_references is null)
62-
throw new Exception("Compilation assemblies not loaded.");
67+
return (null, ["Compilation assemblies still loading. Please wait until complete and try again."]);
6368

6469
var fullSource = lesson.ContextCode
6570
.Replace("/* USER CODE */", userCode);

0 commit comments

Comments
 (0)