Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Fix FluentValidationFilter - null reference exception

support6573080d612e
diff --git a/src/Core/Grand.Infrastructure/Validators/FluentValidationFilter.cs b/src/Core/Grand.Infrastructure/Validators/FluentValidationFilter.cs
index 325a7d703..0861fade8 100644
--- a/src/Core/Grand.Infrastructure/Validators/FluentValidationFilter.cs
+++ b/src/Core/Grand.Infrastructure/Validators/FluentValidationFilter.cs
@@ -38,8 +38,8 @@ namespace Grand.Infrastructure.Validators
await next();
return;
}
-
- foreach (var argument in context.ActionArguments.Where(x => !IsSimpleType(x.Value.GetType())))
+
+ foreach (var argument in context.ActionArguments.Where(x => !IsSimpleType(x.Value?.GetType())))
{
Type genericType = typeof(IValidator<>).MakeGenericType(argument.Value!.GetType());
var validator = (IValidator)_serviceProvider.GetService(genericType);
@@ -58,8 +58,11 @@ namespace Grand.Infrastructure.Validators
await next();
}
- private static bool IsSimpleType(Type type)
+ private static bool IsSimpleType(Type? type)
{
+ if (type == null)
+ return true;
+
return
type.IsPrimitive ||
new Type[] {