Skip to content

Commit f4c7446

Browse files
committed
try to handle error while running as GitHub Pages verse dev that works�GetReferenceAssembliesStreamsAsync: kevmoens.github.io:443/Ellabit/_framework/System.Private.Runtime.InteropServices.JavaScript.dll =net_http_message_not_success_statuscode, 404, Not Found
1 parent 3ab2970 commit f4c7446

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

Ellabit/DynamicCode/SimpleUnloadableAssemblyLoadContext.cs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public void Dispose()
5050
var writer = Activator.CreateInstance(twriter);
5151

5252
var result = ExecuteWithTimeLimit(
53-
new TimeSpan(0,0,15)
54-
, new Func<object?>(() => method?.Invoke(writer, new object[] { }) )
53+
new TimeSpan(0, 0, 15)
54+
, new Func<object?>(() => method?.Invoke(writer, new object[] { }))
5555
);
5656
if (!result.IsCompleted)
5757
{
@@ -71,15 +71,16 @@ public void Dispose()
7171
return ((bool pass, string message))output;
7272
}
7373
catch (Exception ex)
74-
{
74+
{
7575
if (ex is IOException)
76-
{
76+
{
7777
throw new IOException(ex.Message);
78-
} else
79-
{
78+
}
79+
else
80+
{
8081
throw new Exception(ex.Message);
81-
}
82-
}
82+
}
83+
}
8384
}
8485
public static (bool IsCompleted, object? Output) ExecuteWithTimeLimit(TimeSpan timeSpan, Func<object?> codeBlock)
8586
{
@@ -108,7 +109,7 @@ public static (bool IsCompleted, object? Output) ExecuteWithTimeLimit(TimeSpan t
108109
Assembly? assembly = null;
109110
try
110111
{
111-
assembly = this.Assemblies.FirstOrDefault(asm => asm.FullName == "EllabitChallenge, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
112+
assembly = this.Assemblies.FirstOrDefault(asm => asm.FullName == "EllabitChallenge, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
112113

113114
}
114115
catch { }
@@ -129,7 +130,7 @@ public static (bool IsCompleted, object? Output) ExecuteWithTimeLimit(TimeSpan t
129130
treeItems.Add(codeTestTree);
130131
}
131132
string assemblyName = Path.GetFileName("EllabitChallenge");
132-
133+
133134
Assembly[] referenceAssemblyRoots = new[]
134135
{
135136
typeof(AssemblyTargetedPatchBandAttribute).Assembly, // System.Private.CoreLib
@@ -143,7 +144,7 @@ public static (bool IsCompleted, object? Output) ExecuteWithTimeLimit(TimeSpan t
143144
typeof(WebAssemblyHostBuilder).Assembly, // Microsoft.AspNetCore.Components.WebAssembly
144145
typeof(System.Drawing.Color).Assembly,
145146
};
146-
147+
147148
List<string> referenceAssemblyNames = referenceAssemblyRoots
148149
.SelectMany(a => a.GetReferencedAssemblies().Concat(new[] { a.GetName() }))
149150
.Select(an => an.Name ?? "")
@@ -184,7 +185,7 @@ public static (bool IsCompleted, object? Output) ExecuteWithTimeLimit(TimeSpan t
184185
line = diagnostic.Location.GetLineSpan().StartLinePosition.Line;
185186
}
186187
error += $"{diagnostic?.Id} {diagnostic?.GetMessage()}\n line: {line}";
187-
188+
188189
}
189190
throw new IOException(error);
190191
}
@@ -200,7 +201,7 @@ public static (bool IsCompleted, object? Output) ExecuteWithTimeLimit(TimeSpan t
200201

201202
private async Task<IEnumerable<Stream>> GetReferenceAssembliesStreamsAsync(IEnumerable<string> referenceAssemblyNames)
202203
{
203-
if(client == null)
204+
if (client == null)
204205
{
205206
return new Stream[] { };
206207
}
@@ -210,26 +211,31 @@ await Task.WhenAll(
210211
referenceAssemblyNames.Select(async assemblyName =>
211212
{
212213
HttpResponseMessage? result = null;
214+
bool hasError = false;
213215
try
214216
{
215217
result = await client.GetAsync($"/_framework/{assemblyName}.dll");
216218

217219
result.EnsureSuccessStatusCode();
218-
} catch
220+
}
221+
catch
219222
{
220223
try
221224
{
222225
result = await client.GetAsync($"/Ellabit/_framework/{assemblyName}.dll");
223226

224-
result.EnsureSuccessStatusCode();
227+
result.EnsureSuccessStatusCode();
225228
}
226229
catch (Exception ex)
227230
{
228-
throw new Exception($"GetReferenceAssembliesStreamsAsync: { result?.RequestMessage?.RequestUri?.Host}:{ result?.RequestMessage?.RequestUri?.Port}{ result?.RequestMessage?.RequestUri?.AbsolutePath} =" + ex.Message);
231+
hasError = true;
232+
//throw new Exception($"GetReferenceAssembliesStreamsAsync: {result?.RequestMessage?.RequestUri?.Host}:{result?.RequestMessage?.RequestUri?.Port}{result?.RequestMessage?.RequestUri?.AbsolutePath} =" + ex.Message);
229233
}
230234
}
231-
232-
streams.Add(await result.Content.ReadAsStreamAsync());
235+
if (!hasError)
236+
{
237+
streams.Add(await result.Content.ReadAsStreamAsync());
238+
}
233239
}));
234240

235241
return streams;

0 commit comments

Comments
 (0)