This repository was archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
Model binding, BindNeverAttribute and BindAttribute ignored ? #5633
Copy link
Copy link
Closed
Description
Hi,
I have a model with some "get properties" depending on other properties of the model
public Group Group => Device.Group;
These properties are not meant to be binded but its seems they are accessed during binding process. So in my case I got a crash due to a null exception.
System.NullReferenceException: Object reference not set to an instance of an object.
at XXXXXXX.XXXXXXModel.get_Group() in /XXXXX/XXXXModel.cs:line 44
at Microsoft.Extensions.Internal.PropertyHelper.CallNullSafePropertyGetter[TDeclaringType,TValue](Func`2 getter, Object target)
at Microsoft.AspNetCore.Mvc.Internal.DefaultComplexObjectValidationStrategy.Enumerator.MoveNext()
at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.VisitChildren(IValidationStrategy strategy)
at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.VisitComplexType()
at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.Visit(ModelMetadata metadata, String key, Object model)
at Microsoft.AspNetCore.Mvc.Internal.DefaultControllerArgumentBinder.<BindModelAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.DefaultControllerArgumentBinder.<BindArgumentsCoreAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextExceptionFilterAsync>d__24.MoveNext()
Object reference not set to an instance of an object.
I tried to add [BindNever] on the property, and I also try [Bind("List","Of","Property","To","Bind")] on the model but I still get this error.
How can I fix this without adding check on every get property to handle this case ?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels