Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extensions are not working properly in NetStandard2.0 #307

Open
wkirschenmann opened this issue May 25, 2024 · 0 comments
Open

Extensions are not working properly in NetStandard2.0 #307

wkirschenmann opened this issue May 25, 2024 · 0 comments

Comments

@wkirschenmann
Copy link

wkirschenmann commented May 25, 2024

When passing an empty string as the module name, a NullReferenceException is thrown at System.Text.UTF8Encoding.GetBytes(Char* chars, Int32 charCount, Byte* bytes, Int32 byteCount) in System.Text\UTF8Encoding.cs:line 433

This comes from the following code

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static unsafe int GetBytes(this Encoding encoding, string chars, Span<byte> bytes)
        {
            fixed (char* charsPtr = chars)
            fixed (byte* bytesPtr = bytes)
            {
                return encoding.GetBytes(charsPtr, chars.Length, bytesPtr, bytes.Length);
            }
        }

at Wasmtime.Extensions.GetBytes(Encoding encoding, String chars, Span<byte> bytes) in Wasmtime\Extensions.cs

I'd suggest adding the following at the beginning of the GetBytes functions:

if (chars.Length == 0 && bytes.Length == 0) 
  return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant