From 78024a4e32bcfa8647562ccf7db939c7da60d77d Mon Sep 17 00:00:00 2001 From: yanguojin Date: Mon, 27 Nov 2023 19:33:47 +0800 Subject: [PATCH] Fix error and return text parsing error. --- .../csharp/exception/handle_exception.cs | 37 ++++++++++--------- .../csharp/native_methods/ov_common.cs | 2 +- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/modules/csharp_api/csharp/exception/handle_exception.cs b/modules/csharp_api/csharp/exception/handle_exception.cs index 92f2581f7..10805f825 100644 --- a/modules/csharp_api/csharp/exception/handle_exception.cs +++ b/modules/csharp_api/csharp/exception/handle_exception.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; @@ -100,7 +101,7 @@ public static void handler(ExceptionStatus status) { /// /// general error! private static void general_error() { - throw new OVException(ExceptionStatus.GENERAL_ERROR, NativeMethods.ov_get_last_err_msg()); + throw new OVException(ExceptionStatus.GENERAL_ERROR, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg())); } /// /// Throw NOT_IMPLEMENTED OpenVINOException. @@ -108,7 +109,7 @@ private static void general_error() { /// not implemented! private static void not_implemented() { - throw new OVException(ExceptionStatus.NOT_IMPLEMENTED, NativeMethods.ov_get_last_err_msg()); + throw new OVException(ExceptionStatus.NOT_IMPLEMENTED, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg())); } /// @@ -117,7 +118,7 @@ private static void not_implemented() /// network not loaded! private static void network_not_loaded() { - throw new OVException(ExceptionStatus.NETWORK_NOT_LOADED, NativeMethods.ov_get_last_err_msg()); + throw new OVException(ExceptionStatus.NETWORK_NOT_LOADED, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg())); } @@ -127,7 +128,7 @@ private static void network_not_loaded() /// parameter mismatch! private static void parameter_mismatch() { - throw new OVException(ExceptionStatus.PARAMETER_MISMATCH, NativeMethods.ov_get_last_err_msg()); + throw new OVException(ExceptionStatus.PARAMETER_MISMATCH, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg())); } /// @@ -136,7 +137,7 @@ private static void parameter_mismatch() /// not found! private static void not_found() { - throw new OVException(ExceptionStatus.NOT_FOUND, NativeMethods.ov_get_last_err_msg()); + throw new OVException(ExceptionStatus.NOT_FOUND, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg())); } /// @@ -145,7 +146,7 @@ private static void not_found() /// out of bounds! private static void out_of_bounds() { - throw new OVException(ExceptionStatus.OUT_OF_BOUNDS, NativeMethods.ov_get_last_err_msg()); + throw new OVException(ExceptionStatus.OUT_OF_BOUNDS, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg())); } @@ -155,7 +156,7 @@ private static void out_of_bounds() /// unexpection! private static void unexpection() { - throw new OVException(ExceptionStatus.UNEXPECTED, NativeMethods.ov_get_last_err_msg()); + throw new OVException(ExceptionStatus.UNEXPECTED, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg())); } @@ -166,7 +167,7 @@ private static void unexpection() /// request busy! private static void request_busy() { - throw new OVException(ExceptionStatus.REQUEST_BUSY, NativeMethods.ov_get_last_err_msg()); + throw new OVException(ExceptionStatus.REQUEST_BUSY, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg())); } /// /// Throw RESULT_NOT_READY OpenVINOException. @@ -174,7 +175,7 @@ private static void request_busy() /// result not ready! private static void result_not_ready() { - throw new OVException(ExceptionStatus.RESULT_NOT_READY, NativeMethods.ov_get_last_err_msg()); + throw new OVException(ExceptionStatus.RESULT_NOT_READY, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg())); } /// /// Throw OpenVINOException. @@ -182,7 +183,7 @@ private static void result_not_ready() /// not allocated! private static void not_allocated() { - throw new OVException(ExceptionStatus.NOT_ALLOCATED, NativeMethods.ov_get_last_err_msg()); + throw new OVException(ExceptionStatus.NOT_ALLOCATED, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg())); } /// /// Throw INFER_NOT_STARTED OpenVINOException. @@ -190,7 +191,7 @@ private static void not_allocated() /// infer not started! private static void infer_not_started() { - throw new OVException(ExceptionStatus.INFER_NOT_STARTED, NativeMethods.ov_get_last_err_msg()); + throw new OVException(ExceptionStatus.INFER_NOT_STARTED, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg())); } /// /// Throw NETWORK_NOT_READ OpenVINOException. @@ -198,7 +199,7 @@ private static void infer_not_started() /// netword not read! private static void netword_not_read() { - throw new OVException(ExceptionStatus.NETWORK_NOT_READ, NativeMethods.ov_get_last_err_msg()); + throw new OVException(ExceptionStatus.NETWORK_NOT_READ, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg())); } /// /// Throw INFER_CANCELLED OpenVINOException. @@ -206,7 +207,7 @@ private static void netword_not_read() /// infer cancelled! private static void infer_cancelled() { - throw new OVException(ExceptionStatus.INFER_CANCELLED, NativeMethods.ov_get_last_err_msg()); + throw new OVException(ExceptionStatus.INFER_CANCELLED, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg())); } /// /// Throw INVALID_C_PARAM OpenVINOException. @@ -214,7 +215,7 @@ private static void infer_cancelled() /// invalid c param! private static void invalid_c_param() { - throw new OVException(ExceptionStatus.INVALID_C_PARAM, NativeMethods.ov_get_last_err_msg()); + throw new OVException(ExceptionStatus.INVALID_C_PARAM, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg())); } /// /// Throw UNKNOWN_C_ERROR OpenVINOException. @@ -222,7 +223,7 @@ private static void invalid_c_param() /// unknown c error! private static void unknown_c_error() { - throw new OVException(ExceptionStatus.UNKNOWN_C_ERROR, NativeMethods.ov_get_last_err_msg()); + throw new OVException(ExceptionStatus.UNKNOWN_C_ERROR, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg())); } /// /// Throw NOT_IMPLEMENT_C_METHOD OpenVINOException. @@ -230,7 +231,7 @@ private static void unknown_c_error() /// not implement c method! private static void not_implement_c_method() { - throw new OVException(ExceptionStatus.NOT_IMPLEMENT_C_METHOD, NativeMethods.ov_get_last_err_msg()); + throw new OVException(ExceptionStatus.NOT_IMPLEMENT_C_METHOD, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg())); } /// /// Throw UNKNOW_EXCEPTION OpenVINOException. @@ -238,7 +239,7 @@ private static void not_implement_c_method() /// unknown exception! private static void unknown_exception() { - throw new OVException(ExceptionStatus.UNKNOW_EXCEPTION, NativeMethods.ov_get_last_err_msg()); + throw new OVException(ExceptionStatus.UNKNOW_EXCEPTION, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg())); } /// /// Throw PTR_NULL OpenVINOException. @@ -246,7 +247,7 @@ private static void unknown_exception() /// private static void ptr_null_exception() { - throw new OVException(ExceptionStatus.UNKNOW_EXCEPTION, NativeMethods.ov_get_last_err_msg()); + throw new OVException(ExceptionStatus.UNKNOW_EXCEPTION, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg())); } } } diff --git a/modules/csharp_api/csharp/native_methods/ov_common.cs b/modules/csharp_api/csharp/native_methods/ov_common.cs index 9e4bf2711..0a0ff31e7 100644 --- a/modules/csharp_api/csharp/native_methods/ov_common.cs +++ b/modules/csharp_api/csharp/native_methods/ov_common.cs @@ -33,6 +33,6 @@ public partial class NativeMethods /// The last error msg. [DllImport(dll_extern, EntryPoint = "ov_get_last_err_msg", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] - public extern static string ov_get_last_err_msg(); + public extern static IntPtr ov_get_last_err_msg(); } }