Commit d95df66
Fix IndexOutOfRangeException reading inherited return-parameter description on .NET Framework
On .NET Framework, reading an inherited [Description] from the return
parameter of an overriding method throws IndexOutOfRangeException:
System.Attribute.GetParentDefinition indexes the result of GetParameters()
with the return parameter's Position, which is -1. GetReturnParameterDescription
calls GetCustomAttribute(inherit: true) on method.ReturnParameter, so any
AIFunction created from such an override would throw instead of producing a
schema.
Modern .NET already guards this case (returning the base method's return
parameter), so the failure is .NET Framework only and cannot be fixed there.
Extend the existing catch filter to also treat IndexOutOfRangeException as
"description absent", alongside the DynamicMethod ArgumentNullException/
NullReferenceException cases. On .NET Framework the inherited return
description is silently dropped; on modern .NET it is preserved.
Add a dedicated regression test with TFM-conditional assertions covering the
method-level, ordinary-parameter, and return-parameter inherited descriptions
on an overriding method.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent ec522c2 commit d95df66
2 files changed
Lines changed: 40 additions & 3 deletions
File tree
- src/Libraries/Microsoft.Extensions.AI.Abstractions/Functions
- test/Libraries/Microsoft.Extensions.AI.Tests/Functions
Lines changed: 5 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1003 | 1003 | | |
1004 | 1004 | | |
1005 | 1005 | | |
1006 | | - | |
| 1006 | + | |
1007 | 1007 | | |
1008 | 1008 | | |
1009 | 1009 | | |
| |||
1221 | 1221 | | |
1222 | 1222 | | |
1223 | 1223 | | |
1224 | | - | |
| 1224 | + | |
1225 | 1225 | | |
1226 | | - | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
1227 | 1229 | | |
1228 | 1230 | | |
1229 | 1231 | | |
| |||
Lines changed: 35 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
1068 | 1069 | | |
1069 | 1070 | | |
1070 | 1071 | | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
1071 | 1106 | | |
1072 | 1107 | | |
1073 | 1108 | | |
| |||
0 commit comments