@@ -8,6 +8,7 @@ namespace LearnJsonEverything.Services;
88public 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