diff --git a/src/PolyType.Roslyn/ModelGenerator/TypeDataModelGenerator.Object.cs b/src/PolyType.Roslyn/ModelGenerator/TypeDataModelGenerator.Object.cs index ebc97837..0264eef6 100644 --- a/src/PolyType.Roslyn/ModelGenerator/TypeDataModelGenerator.Object.cs +++ b/src/PolyType.Roslyn/ModelGenerator/TypeDataModelGenerator.Object.cs @@ -318,16 +318,16 @@ private ImmutableArray MapConstructors(INamedTypeSymbol ty { Debug.Assert(constructor.MethodKind is MethodKind.Constructor || constructor.IsStatic); + // Skip constructors with out parameters - they cannot be meaningfully invoked through the shape system + if (constructor.Parameters.Any(p => p.RefKind is RefKind.Out)) + { + return null; + } + var parameters = new List(); TypeDataModelGenerationContext scopedCtx = ctx; foreach (IParameterSymbol parameter in constructor.Parameters) { - if (parameter.RefKind is RefKind.Out) - { - // Skip constructors with out parameters - return null; - } - if (IncludeNestedType(parameter.Type, ref scopedCtx) != TypeDataModelGenerationStatus.Success) { // Skip constructors with unsupported parameter types diff --git a/src/PolyType.Roslyn/ModelGenerator/TypeDataModelGenerator.cs b/src/PolyType.Roslyn/ModelGenerator/TypeDataModelGenerator.cs index 717b6dee..0e76875a 100644 --- a/src/PolyType.Roslyn/ModelGenerator/TypeDataModelGenerator.cs +++ b/src/PolyType.Roslyn/ModelGenerator/TypeDataModelGenerator.cs @@ -452,6 +452,7 @@ protected virtual TypeDataModelGenerationStatus MapMethod(ResolvedMethodSymbol r { if (parameter.RefKind is RefKind.Out) { + // Methods with out parameters are not supported result = default; return TypeDataModelGenerationStatus.UnsupportedType; } diff --git a/src/PolyType/ReflectionProvider/ReflectionObjectTypeShape.cs b/src/PolyType/ReflectionProvider/ReflectionObjectTypeShape.cs index 5b32f3cf..2fd75c8b 100644 --- a/src/PolyType/ReflectionProvider/ReflectionObjectTypeShape.cs +++ b/src/PolyType/ReflectionProvider/ReflectionObjectTypeShape.cs @@ -260,9 +260,17 @@ static MemberInitializerShapeInfo[] GetSettableMembers(PropertyShapeInfo[] allMe } ParameterInfo[] parameters = constructorInfo.GetParameters(); - if (parameters.Any(param => param.IsOut || !param.GetEffectiveParameterType().CanBeGenericArgument())) + + // Skip constructors with out parameters - they cannot be meaningfully invoked through the shape system + if (parameters.Any(param => param.IsOut)) + { + continue; + } + + // Filter out any unsupported parameter types + if (parameters.Any(param => !param.GetEffectiveParameterType().CanBeGenericArgument())) { - // Skip constructors with unsupported parameter types or out parameters + // Skip constructors with unsupported parameter types continue; } diff --git a/src/PolyType/ReflectionProvider/ReflectionTypeShapeProvider.cs b/src/PolyType/ReflectionProvider/ReflectionTypeShapeProvider.cs index c3b240d1..1a2fd9d0 100644 --- a/src/PolyType/ReflectionProvider/ReflectionTypeShapeProvider.cs +++ b/src/PolyType/ReflectionProvider/ReflectionTypeShapeProvider.cs @@ -968,6 +968,8 @@ internal static MethodShapeInfo CreateMethodShapeInfo( } ParameterInfo[] parameters = methodInfo.GetParameters(); + + // Check for unsupported parameter types including out parameters if (parameters.FirstOrDefault(param => param.IsOut || !param.GetEffectiveParameterType().CanBeGenericArgument()) is { } param) { throw new NotSupportedException($"Method '{methodInfo}' contains unsupported parameter type '{param.Name}'.");