Skip to content

Commit

Permalink
Return null when Variant contains BSTR
Browse files Browse the repository at this point in the history
I found this one when implement VARIANT marshalling for NativeAOT. Without that I have to resort to duplicate implementation in that class.
PR where I discover this - dotnet/runtimelab#1142
Problem is `Marshal.PtrToStringBSTR` throw exception when passed `IntPtr.Zero`, but `Marshal.StringToBSTR` produce `IntPtr.Zero` when given null.
  • Loading branch information
kant2002 committed May 20, 2021
1 parent 636f89d commit 2522ccd
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,10 @@ public string AsBstr
get
{
Debug.Assert(VariantType == VarEnum.VT_BSTR);
if (_typeUnion._unionTypes._bstr == IntPtr.Zero)
{
return null;
}
return (string)Marshal.PtrToStringBSTR(this._typeUnion._unionTypes._bstr);
}
set
Expand Down

0 comments on commit 2522ccd

Please sign in to comment.