Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

Commented Issue: Activator.CreateInstance Problem [7119]

$
0
0
The following line of code when debugging finds the correct custom validator and steps into it's constructor and immediately throws a "Target of Invocation Exception". The inner exception states "operation may destabilize the runtime".<br /><br /> public class EntityBase<TSource><br /> {<br /> public IList<ValidationError> ValidationErrors { get; protected set; }<br /><br /> public AbstractValidator<TSource> Validator { get; protected set; }<br /><br /> public bool Validate(TSource entity)<br /> {<br /> var entityValidator = Activator.CreateInstance(entity.GetType().BaseType.Assembly.GetName().Name, string.Format(entity.GetType().BaseType.Assembly.GetName().Name + ".{0}.Validators.{0}Validator", entity.GetType().BaseType.Name)).Unwrap();<br /> }<br /><br />The class that is being invoked is not in the same assembly and the assembly is not referenced in the project where this call above happens because it would cause a circular reference.<br /><br />Any help would be greatly appreciated.
Comments: Yes, I had a play with the sample and found the issue. This is caused by a bug in .NET 4.5. A workaround was introduced in FluentValidation 3.4 - please upgrade to the latest version as you're running an old build (3.1).

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>