I got some C++ library. And also I got C++/CLI wrapper for it, to make it possible call methods from this library in C# code.
Lets say I would like to use some call in C# like this:
string date = MyWrapper.GetValue("SystemSettings", "BuildDate", null);
which will call next function on C++/CLI:
static String^ GetValue(String^ section, String^ key, String^ defaultValue)
My problem: I got next ArgumentNullException:
Value cannot be null.\r\nParameter name: managedString.
So... Question: how should I pass null
correctly?
Thanks.
Your code that passes null is fine. The problem is that your wrapper code needs to detect null and deal with it. That code is presumably written under the assumption that the third parameter is never null. If you wish to allow null, you must explicitly handle that condition:
static String^ GetValue(String^ section, String^ key, String^ defaultValue)
{
if (defaultValue == nullptr)
// special case handling
....
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With