@@ -67,7 +67,7 @@ public void BindMemberFromValue(PropertyInfo property, IValueDescriptor valueDes
6767
6868 private ( bool success , object ? newInstance , bool anyNonDefaults ) CreateInstanceInternal ( BindingContext bindingContext )
6969 {
70- if ( DisallowedBindingType ( ) )
70+ if ( IsModelTypeUnbindable ( ) )
7171 {
7272 throw new InvalidOperationException ( $ "The type { ModelDescriptor . ModelType } cannot be bound") ;
7373 }
@@ -93,11 +93,11 @@ public void BindMemberFromValue(PropertyInfo property, IValueDescriptor valueDes
9393 }
9494 }
9595
96- private bool DisallowedBindingType ( )
96+ private bool IsModelTypeUnbindable ( )
9797 {
9898 var modelType = ModelDescriptor . ModelType ;
99- return modelType . IsConstructedGenericTypeOf ( typeof ( Span < > ) ) ||
100- modelType . IsConstructedGenericTypeOf ( typeof ( ReadOnlySpan < > ) ) ;
99+ return modelType . IsConstructedGenericTypeOf ( typeof ( Span < > ) ) ||
100+ modelType . IsConstructedGenericTypeOf ( typeof ( ReadOnlySpan < > ) ) ;
101101 }
102102
103103 private bool ShortCutTheBinding ( )
@@ -258,6 +258,8 @@ internal static (BoundValue? boundValue, bool usedNonDefault) GetBoundValue(
258258 bool includeMissingValues ,
259259 Type ? parentType )
260260 {
261+
262+
261263 if ( bindingContext . TryBindToScalarValue (
262264 valueDescriptor ,
263265 valueSource ,
@@ -276,7 +278,14 @@ internal static (BoundValue? boundValue, bool usedNonDefault) GetBoundValue(
276278 if ( valueDescriptor . ValueType != parentType ) // Recursive models aren't allowed
277279 {
278280 var binder = bindingContext . GetModelBinder ( valueDescriptor ) ;
281+
282+ if ( binder . IsModelTypeUnbindable ( ) )
283+ {
284+ return ( null , false ) ;
285+ }
286+
279287 var ( success , newInstance , usedNonDefaults ) = binder . CreateInstanceInternal ( bindingContext ) ;
288+
280289 if ( success )
281290 {
282291 return ( new BoundValue ( newInstance , valueDescriptor , valueSource ) , usedNonDefaults ) ;
@@ -287,14 +296,13 @@ internal static (BoundValue? boundValue, bool usedNonDefault) GetBoundValue(
287296 {
288297 return ( new BoundValue ( parameterDescriptor . GetDefaultValue ( ) , valueDescriptor , valueSource ) , false ) ;
289298 }
290- // Logic dropped here - misnamed and purpose unclear: ShouldPassNullToConstructor(constructorDescriptor.Parent, constructorDescriptor))
299+
291300 return ( BoundValue . DefaultForType ( valueDescriptor ) , false ) ;
292301 }
293302
294303 return ( null , false ) ;
295304 }
296305
297-
298306 protected ConstructorDescriptor FindModelConstructorDescriptor ( ConstructorInfo constructorInfo )
299307 {
300308 var constructorParameters = constructorInfo . GetParameters ( ) ;
0 commit comments