Open
Description
Input code
In unsafe context
public class CSharpClass
{
public static void Main(){
byte[] bytes = [1, 2, 3];
fixed (byte* bufferPtr = bytes)
{
Console.WriteLine($"The address of the first array element: {(long)bufferPtr:X}.");
Console.WriteLine($"The value of the first array element: {*bufferPtr}.");
}
}
}
Erroneous output
Public Class CSharpClass
Public Shared Sub Main()
If True Then
Dim bytes As Byte() = _(1, 2, 3)
''' Cannot convert FixedStatementSyntax, CONVERSION ERROR: Conversion for FixedStatement not implemented, please report this issue in 'fixed (byte* bufferPtr = by...' at character 91
'''
'''
''' Input:
''' fixed (byte* bufferPtr = bytes)
''' {
''' Console.WriteLine($"The address of the first array element: {(long)bufferPtr:X}.");
''' Console.WriteLine($"The value of the first array element: {*bufferPtr}.");
''' }
'''
'''
End If
End Sub
End Class
Expected output
Imports System
Imports System.Runtime.InteropServices
Module Program
Public Shared Sub Main()
Dim bytes As Byte() = {1, 2, 3}
Dim bufferHandle As GCHandle = GCHandle.Alloc(bytes, GCHandleType.Pinned)
Try
Dim bufferPtr As IntPtr = bufferHandle.AddrOfPinnedObject()
Console.WriteLine($"The address of the first array element: {bufferPtr.ToInt64():X}.")
Console.WriteLine($"The value of the first array element: {Marshal.ReadByte(bufferPtr)}.")
Finally
bufferHandle.Free()
End Try
End Sub
End Module
Details
- Product in use: e.g. icsharpcode.github.io/CodeConverter / VS extension / both
- Version in use: e.g. 5.6.3 or a commit hash (if it's a 3rd party tool using this library, try one of the above)
- Did you see it working in a previous version, which?
- Any other relevant information to the issue, or your interest in contributing a fix.