-
Notifications
You must be signed in to change notification settings - Fork 418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error handling when loading assemblies from an external folder #866
Changes from all commits
76906f9
0cbaf04
18b16dd
8ffc3c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,17 +38,26 @@ public IReadOnlyList<Assembly> LoadAllFrom(string folderPath) | |
{ | ||
if (string.IsNullOrWhiteSpace(folderPath)) return Array.Empty<Assembly>(); | ||
|
||
var assemblies = new List<Assembly>(); | ||
foreach (var filePath in Directory.EnumerateFiles(folderPath, "*.dll")) | ||
try | ||
{ | ||
var assembly = LoadFromPath(filePath); | ||
if (assembly != null) | ||
var assemblies = new List<Assembly>(); | ||
|
||
foreach (var filePath in Directory.EnumerateFiles(folderPath, "*.dll")) | ||
{ | ||
assemblies.Add(assembly); | ||
var assembly = LoadFromPath(filePath); | ||
if (assembly != null) | ||
{ | ||
assemblies.Add(assembly); | ||
} | ||
} | ||
} | ||
|
||
return assemblies; | ||
return assemblies; | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.LogError(ex, $"An error occurred when attempting to access '{folderPath}'."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This message could be wrong if something else fails. I can't see what would fail though. 😄 Is there any reason not to check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had it in the initial commit (76906f9) but then I decided to go for try/catch instead as that would cover a lot more potential edge cases i.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough. |
||
return Array.Empty<Assembly>(); | ||
} | ||
} | ||
|
||
private Assembly LoadFromPath(string assemblyPath) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this should be
SearchOption.AllDirectories
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather that be passed in. Could be surprising behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah maybe it's too much at all to even think about it. let's keep it simple for now and when/if more advanced use cases come up then we can decide what to do (i.e. allow this setting to be bound from config too and so on)