4

I am writing a simple app in WinRT and would like the C++ bit to do some processing. I want to be able to pass null if the function is to ignore the parameter as an empty string means something as well as a value.

My C# code:

UnsafeNativeMethods.TestString(null);

My C++ code:

void UnsafeNativeMethods::TestString(String^ test)
{
}

I keep getting a NullReferenceException in the System.StubHelpers.HStringMarshaler.ConvertToNativeReference.

Is there a way to pass null to this method at all?

EDIT AGAIN

The is about all I have:

public ref class UnsafeNativeMethods sealed
{
public:
    static void TestString(Platform::String^ test);
};

I just created a new Windows Phone 8 app and this is the complete exception:

System.ArgumentNullException: Value cannot be null.
    at System.StubHelpers.HStringMarshaler.ConvertToNativeReference(String managed, HSTRING_HEADER* hstringHeader)
    at WindowsPhoneRuntimeComponent1.UnsafeNativeMethods.TestString(String test)
    at PhoneApp2.MainPage..ctor()

There is no fancy code anywhere, just the above code and a brand new project (a C# WP8 App and a WP Runtime Component project)

Matthew
  • 4,832
  • 2
  • 29
  • 55

0 Answers0