For example: 1 parameter acquired but value is empty, it turn unhanded exception and Controller not invoked.
If add in JsonModelBinder.cs: 43 fix below, Controller will be invoked and parameter == null as is.
// Add null check for parameter
if (string.IsNullOrEmpty(serialized))
{
bindingContext.Result = ModelBindingResult.Success(null);
return Task.CompletedTask;
}
Before fix:
System.ArgumentNullException: Value cannot be null. (Parameter 'instance') at System.ComponentModel.TypeDescriptor.GetReflectionType(Object instance) at BrunoZell.ModelBinding.JsonModelBinder.BindModelAsync(ModelBindingContext bindingContext) in C:\Users\b.yanish\source\repos\JsonModelBinder\src\JsonModelB inder\JsonModelBinder.cs:line 59 at Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BinderTypeModelBinder.BindMo delAsync(ModelBindingContext bindingContext) at Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder.BindModelAsync(Actio nContext actionContext, IModelBinder modelBinder, IValueProvider valueProvider, ParameterDescriptor parameter, ModelMetadata metadata, Object value) at Microsoft.AspNetCore.Mvc.Controllers.ControllerBinderDelegateProvider.<>c_ _DisplayClass0_0.<<CreateBinderDelegate>g__Bind|0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInn erFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, St ate next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourc eFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scop e scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceEx ecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipel ineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Sco pe scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Aw aited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTas k|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpCont ext context) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.Proces sRequests[TContext](IHttpApplication1 application)
`
For example: 1 parameter acquired but value is empty, it turn unhanded exception and Controller not invoked.
If add in JsonModelBinder.cs: 43 fix below, Controller will be invoked and parameter == null as is.
// Add null check for parameter if (string.IsNullOrEmpty(serialized)) { bindingContext.Result = ModelBindingResult.Success(null); return Task.CompletedTask; }
Before fix:
System.ArgumentNullException: Value cannot be null. (Parameter 'instance') at System.ComponentModel.TypeDescriptor.GetReflectionType(Object instance) at BrunoZell.ModelBinding.JsonModelBinder.BindModelAsync(ModelBindingContext bindingContext) in C:\Users\b.yanish\source\repos\JsonModelBinder\src\JsonModelB inder\JsonModelBinder.cs:line 59 at Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BinderTypeModelBinder.BindMo delAsync(ModelBindingContext bindingContext) at Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder.BindModelAsync(Actio nContext actionContext, IModelBinder modelBinder, IValueProvider valueProvider, ParameterDescriptor parameter, ModelMetadata metadata, Object value) at Microsoft.AspNetCore.Mvc.Controllers.ControllerBinderDelegateProvider.<>c_ _DisplayClass0_0.<<CreateBinderDelegate>g__Bind|0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInn erFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, St ate next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourc eFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scop e scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceEx ecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipel ineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Sco pe scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Aw aited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTas k|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpCont ext context) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.Proces sRequests[TContext](IHttpApplication
1 application) `After fix: