문제

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
    ....
}

다른 팁

There is a similar limitation for Windows Runtime. See this verbose answer to a similar question. Looks like you might have trapped on something very close to it.

Maybe you need to pass an empty string instead of null. For example

string date = MyWrapper.GetValue("SystemSettings", "BuildDate", "");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top