diff --git a/PaddleOCRSharp/PaddleOCREngine.cs b/PaddleOCRSharp/PaddleOCREngine.cs
index 0503bc34cfe8bbd0fa1d0ac10d66c5c25a45ed56..491c22b6696dd57abe987e4e6a3656069af34682 100644
--- a/PaddleOCRSharp/PaddleOCREngine.cs
+++ b/PaddleOCRSharp/PaddleOCREngine.cs
@@ -49,6 +49,7 @@ namespace PaddleOCRSharp
#endregion
#region 文本识别
+
///
/// PaddleOCR识别引擎对象初始化
///
@@ -67,7 +68,7 @@ namespace PaddleOCRSharp
if (parameter == null) parameter = new OCRParameter();
if (config == null)
{
- string root = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
+ string root = PathUtils.GetRootDirectory();
config = new OCRModelConfig();
string modelPathroot = root + @"\inference";
config.det_infer = modelPathroot + @"\ch_PP-OCRv3_det_infer";
diff --git a/PaddleOCRSharp/PaddleStructureEngine.cs b/PaddleOCRSharp/PaddleStructureEngine.cs
index 490e1a6d6807c970e464f9c8f6480b37abe8fda6..230947646aa3a1ce7338d9886b83ceb4f062a843 100644
--- a/PaddleOCRSharp/PaddleStructureEngine.cs
+++ b/PaddleOCRSharp/PaddleStructureEngine.cs
@@ -56,7 +56,7 @@ namespace PaddleOCRSharp
if (parameter == null) parameter = new StructureParameter();
if (config == null)
{
- string root = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
+ string root = PathUtils.GetRootDirectory();
config = new StructureModelConfig();
string modelPathroot = root + @"\inference";
diff --git a/PaddleOCRSharp/PathUtils.cs b/PaddleOCRSharp/PathUtils.cs
new file mode 100644
index 0000000000000000000000000000000000000000..e6bf1bba38f620bcd7826c65ca865002242429fa
--- /dev/null
+++ b/PaddleOCRSharp/PathUtils.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+
+namespace PaddleOCRSharp
+{
+ ///
+ /// 路径相关方法;
+ ///
+ static class PathUtils
+ {
+ ///
+ /// 获取程序的当前路径;
+ ///
+ ///
+ public static string GetRootDirectory()
+ {
+#if NET46_OR_GREATER || NETCOREAPP
+ return AppContext.BaseDirectory;
+#else
+ return Path.GetDirectoryName(typeof(PathUtils).Assembly.Location);
+#endif
+ }
+ }
+}