diff --git a/CMakeLists.txt b/CMakeLists.txt
index bc533dc7..0512038f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project(sherpa-onnx)
-set(SHERPA_ONNX_VERSION "1.4.7")
+set(SHERPA_ONNX_VERSION "1.4.8")
# Disable warning about
#
diff --git a/scripts/dotnet/offline.cs b/scripts/dotnet/offline.cs
index 295f88f7..afbec42a 100644
--- a/scripts/dotnet/offline.cs
+++ b/scripts/dotnet/offline.cs
@@ -4,6 +4,7 @@
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;
+using System.Text;
using System;
namespace SherpaOnnx
@@ -116,7 +117,25 @@ namespace SherpaOnnx
public OfflineRecognizerResult(IntPtr handle)
{
Impl impl = (Impl)Marshal.PtrToStructure(handle, typeof(Impl));
- _text = Marshal.PtrToStringUTF8(impl.Text);
+
+ // PtrToStringUTF8() requires .net standard 2.1
+ // _text = Marshal.PtrToStringUTF8(impl.Text);
+
+ int length = 0;
+
+ unsafe
+ {
+ byte* buffer = (byte*)impl.Text;
+ while (*buffer != 0)
+ {
+ ++buffer;
+ }
+ length = (int)(buffer - (byte*)impl.Text);
+ }
+
+ byte[] stringBuffer = new byte[length];
+ Marshal.Copy(impl.Text, stringBuffer, 0, length);
+ _text = Encoding.UTF8.GetString(stringBuffer);
}
[StructLayout(LayoutKind.Sequential)]
diff --git a/scripts/dotnet/online.cs b/scripts/dotnet/online.cs
index d86d1520..de30f459 100644
--- a/scripts/dotnet/online.cs
+++ b/scripts/dotnet/online.cs
@@ -1,9 +1,10 @@
/// Copyright (c) 2023 Xiaomi Corporation (authors: Fangjun Kuang)
/// Copyright (c) 2023 by manyeyes
-using System.Linq;
using System.Collections.Generic;
+using System.Linq;
using System.Runtime.InteropServices;
+using System.Text;
using System;
namespace SherpaOnnx
@@ -116,7 +117,24 @@ namespace SherpaOnnx
public OnlineRecognizerResult(IntPtr handle)
{
Impl impl = (Impl)Marshal.PtrToStructure(handle, typeof(Impl));
- _text = Marshal.PtrToStringUTF8(impl.Text);
+ // PtrToStringUTF8() requires .net standard 2.1
+ // _text = Marshal.PtrToStringUTF8(impl.Text);
+
+ int length = 0;
+
+ unsafe
+ {
+ byte* buffer = (byte*)impl.Text;
+ while (*buffer != 0)
+ {
+ ++buffer;
+ }
+ length = (int)(buffer - (byte*)impl.Text);
+ }
+
+ byte[] stringBuffer = new byte[length];
+ Marshal.Copy(impl.Text, stringBuffer, 0, length);
+ _text = Encoding.UTF8.GetString(stringBuffer);
}
[StructLayout(LayoutKind.Sequential)]
diff --git a/scripts/dotnet/sherpa-onnx.csproj.in b/scripts/dotnet/sherpa-onnx.csproj.in
index 2f40237e..4063bfe4 100644
--- a/scripts/dotnet/sherpa-onnx.csproj.in
+++ b/scripts/dotnet/sherpa-onnx.csproj.in
@@ -4,7 +4,7 @@
README.md
Library
10.0
- netstandard2.1;netcoreapp3.1;net6.0;net7.0
+ netstandard2.0;netcoreapp3.1;net6.0;net7.0
linux-x64;osx-x64;win-x64
true
sherpa-onnx
diff --git a/scripts/dotnet/sherpa-onnx.csproj.runtime.in b/scripts/dotnet/sherpa-onnx.csproj.runtime.in
index f364f8aa..335254e1 100644
--- a/scripts/dotnet/sherpa-onnx.csproj.runtime.in
+++ b/scripts/dotnet/sherpa-onnx.csproj.runtime.in
@@ -3,7 +3,7 @@
Apache-2.0
README.md
Library
- netstandard2.0;netcoreapp3.1;net6.0
+ netstandard2.0;netcoreapp3.1;net6.0;net7.0
{{ dotnet_rid }}
sherpa-onnx
{{ version }}