@@ -8,6 +8,7 @@ namespace LearnJsonEverything.Services;
8
8
public static class CompilationHelpers
9
9
{
10
10
private static MetadataReference [ ] ? _references ;
11
+ private static bool _isLoading ;
11
12
12
13
private static readonly string [ ] EnsuredAssemblies =
13
14
[
@@ -18,10 +19,13 @@ public static class CompilationHelpers
18
19
"Yaml2JsonNode" ,
19
20
] ;
20
21
21
- public static async Task < MetadataReference [ ] > LoadAssemblyReferences ( HttpClient client )
22
+ public static async Task < MetadataReference [ ] ? > LoadAssemblyReferences ( HttpClient client )
22
23
{
23
24
if ( _references is null )
24
25
{
26
+ if ( _isLoading ) return null ;
27
+ _isLoading = true ;
28
+
25
29
var refs = AppDomain . CurrentDomain . GetAssemblies ( ) ;
26
30
var names = refs
27
31
. Where ( x => ! x . IsDynamic )
@@ -51,6 +55,7 @@ public static async Task<MetadataReference[]> LoadAssemblyReferences(HttpClient
51
55
}
52
56
53
57
_references = references ;
58
+ _isLoading = false ;
54
59
}
55
60
56
61
return _references ;
@@ -59,7 +64,7 @@ public static async Task<MetadataReference[]> LoadAssemblyReferences(HttpClient
59
64
public static ( ILessonRunner < T > ? , string [ ] ) GetRunner < T > ( LessonData lesson , string userCode )
60
65
{
61
66
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." ] ) ;
63
68
64
69
var fullSource = lesson . ContextCode
65
70
. Replace ( "/* USER CODE */" , userCode ) ;
0 commit comments