Exception when trying to read null string in C# WinRT component from WinJS

前端 未结 1 1720
无人及你
无人及你 2020-12-17 17:42

I have the following scenario: Data lib in C# compiled as a Windows Runtime component.

One of its classes is looks like this:

public sealed class My         


        
1条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-17 18:05

    The Windows Runtime string type is a value type and has no null value. The .NET projection prohibits passing a null .NET string across the Windows Runtime ABI boundary for this reason.

    The string type used by the Windows Runtime is the HSTRING type. While this type does not have a null value, it does have a null representation (that is, in C++, HSTRING s = nullptr; is valid). An HSTRING with a null representation is an empty string.

    The .NET projection converts this null representation into an empty string (String.Empty) for strings coming in from the ABI boundary, and prohibits actual null .NET strings from being passed back across the ABI boundary.

    0 讨论(0)
提交回复
热议问题