question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception when searching for validators

See original GitHub issue

I haven’t been able to replicate this locally, but have identified this exception from our test envrionment. This appears to happen if a validator isn’t in DI and Blazored FluentValidation scans for it.

I am assuming that this scan is just identifying an existing issue in my solution, but is it possible to handle these errors more gracefully?

System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'System.DirectoryServices.Protocols, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   at Blazored.FluentValidation.EditContextFluentValidationExtensions.GetValidatorForModel(IServiceProvider serviceProvider, Object model)
   at Blazored.FluentValidation.EditContextFluentValidationExtensions.ValidateField(EditContext editContext, ValidationMessageStore messages, FieldIdentifier fieldIdentifier, IServiceProvider serviceProvider, IValidator validator)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__139_0(Object state)
   at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.ExecuteSynchronously(TaskCompletionSource`1 completion, SendOrPostCallback d, Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
chrissaintycommented, Apr 8, 2020

The component wasn’t ever designed to work with that scenario, it was only designed to work with validators registered via DI.

The only way I can see around this is to allow you to pass in a validator instance to use to validate that particular form. I’m not sure how much work that would be. If you could raise that as a separate feature request then it can be looked into.

1reaction
chrissaintycommented, Mar 30, 2020

Are you concerned that if you swallow exceptions during the assembly scan then it may silently fail to resolve validators?

Correct, if an assembly couldn’t be found and that had the validator in it, then we wouldn’t be able to validate the form and there wouldn’t be any clues to anyone as to why.

It contains a child component with no validation, and it is this search which is failing. To work around it, I’ve just registered an empty validator in DI.

That’s interesting. I’ll have a look play around and see if there is anything we can tweak to improve this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

validation - Is it a good or bad idea throwing Exceptions ...
I'd go further and saying validation throwing exceptions isn't the best approach; instead return a Boolean and store a list of validation error ......
Read more >
Replacing Throwing Exceptions with Notification in Validations
I was recently looking at some code to do some basic validation of some incoming JSON messages. It looked something like this. public...
Read more >
If the model is validating the data, shouldn't it throw ...
Controller or presentation layer must decide whether it throws them or it does it's own validations to prevent the exceptions from happening.
Read more >
Validation and exception handling
I have quite a few questions when trying out CAF. Please kindly give me some help. 1. I found that it's suggest to...
Read more >
Validation and Exception Handling with Spring
Whenever I start implementing a new REST API with Spring, I struggle with the decision of how to validate requests and to handle...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found