8000 ParameterInfo.Name needs to be checked for null before usage (#1375) · pythonnet/pythonnet@d86bf3c · GitHub
[go: up one dir, main page]

Skip to content

Commit d86bf3c

Browse files
authored
ParameterInfo.Name needs to be checked for null before usage (#1375)
This occured in trying to use F# code from Python. As the `.Name` property returns `null`, `ContainsKey` fails. Related documentation: https://docs.microsoft.com/en-us/dotnet/api/system.reflection.parameterinfo.name
1 parent 1afae4c commit d86bf3c

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ or the DLL must be loaded in advance. This must be done before calling any other
5656
- `import` may now raise errors with more detail than "No module named X"
5757
- Exception stacktraces on `PythonException.StackTrace` are now properly formatted
5858
- Providing an invalid type parameter to a generic type or method produces a helpful Python error
59+
- Empty parameter names (as can be generated from F#) do not cause crashes
5960

6061
### Removed
6162

src/runtime/methodbinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ static object[] TryConvertArguments(ParameterInfo[] pi, bool paramsArray,
622622
for (int paramIndex = 0; paramIndex < pi.Length; paramIndex++)
623623
{
624624
var parameter = pi[paramIndex];
625-
bool hasNamedParam = kwargDict.ContainsKey(parameter.Name);
625+
bool hasNamedParam = parameter.Name != null ? kwargDict.ContainsKey(parameter.Name) : false;
626626
bool isNewReference = false;
627627

628628
if (paramIndex >= pyArgCount && !(hasNamedParam || (paramsArray && paramIndex == arrayStart)))

0 commit comments

Comments
 (0)
0