3

I'm currently working on a project in Python (for .NET) that calls functions from a C# .dll. There's a nullable type (double?) argument in one of the C# functions and apparently I have to edit the python source code (Creating a C# Nullable Int32 within Python (using Python.NET) to call a C# method with an optional int argument), which I'd prefer not to do in case other people will use this nor do I want to update the C# code to handle this case of conversion.

For now, I've tried the following:

nullable_double = System.Nullable[System.Double]()
func(nullable_double)

This gives me the following error:

ArgumentException: Object of type 'System.RuntimeType' cannot be converted to type 'System.Nullable`1[System.Double]'.

I also tried just passing in 'None' but that didn't work as well. Is there anyway I can do this without changing the python source code or the c# dll?

Community
  • 1
  • 1
cole
  • 63
  • 5

1 Answers1

1

Please check, if the following is working with your func(nullable_double):

import clr
import System

nullable_double = System.Nullable[System.Double](0) # just providing a number for initialization
print(nullable_double) # prints: 0
print(type(nullable_double)) # prints: <class 'System.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'>
mdk
  • 398
  • 2
  • 8