Conversation
…d falling back to GetTypeInfo
Fix: Assembly Scanner Crashes on F#
|
There was a problem hiding this comment.
Pull request overview
This pull request adds robust handling for F# assemblies and other assemblies that may throw ReflectionTypeLoadException when accessing their defined types. The changes introduce a new extension method GetLoadableDefinedTypes that gracefully catches these exceptions and returns only the successfully loaded types.
Changes:
- Added
GetLoadableDefinedTypesextension method to safely access assembly types with exception handling - Updated all assembly type scanning operations to use the new safe method
- Added comprehensive test coverage for assemblies that throw
ReflectionTypeLoadException
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/MediatR/Registration/ServiceRegistrar.cs | Added GetLoadableDefinedTypes extension method that catches ReflectionTypeLoadException and returns loadable types; replaced all direct DefinedTypes accesses with calls to this new method (lines 79, 106, 236, 440) |
| test/MediatR.Tests/MicrosoftExtensionsDI/AssemblyResolutionTests.cs | Added test ShouldNotThrowWhenAssemblyThrowsReflectionTypeLoadException with a mock BrokenAssembly class that simulates F# assembly behavior by throwing ReflectionTypeLoadException |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…d falling back to GetTypeInfo