问题描述

在我准备使用的 Tesseract 来识别验证码的时候,出现了 ArgumentException: 路径的形式不合法。
我翻遍了中文所有内容但是并没有找到解决方案 后来使用英文搜索 发现是 Fody 的问题
Github 问题地址

报错日志

2025-03-24T10:12:55.png

此异常最初是在此调用堆栈中引发的: 
    System.IO.Path.NormalizePath(string, bool, int, bool)
    System.IO.Path.InternalGetDirectoryName(string)
    InteropDotNet.LibraryLoader.CheckExecutingAssemblyDomain(string, string)
    InteropDotNet.LibraryLoader.LoadLibrary(string, string)
    InteropRuntimeImplementer.LeptonicaApiSignaturesInstance.LeptonicaApiSignaturesImplementation.LeptonicaApiSignaturesImplementation(InteropDotNet.LibraryLoader)

具体报错是

System.Reflection.TargetInvocationException
  HResult=0x80131604
  Message=调用的目标发生了异常。
  Source=mscorlib
  StackTrace:
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, Object[] args)
   at InteropDotNet.InteropRuntimeImplementer.CreateInstance[T]()
   at Tesseract.Interop.LeptonicaApi.Initialize()
   at Tesseract.Interop.TessApi.Initialize()
   at Tesseract.Interop.TessApi.get_Native()
   at Tesseract.TesseractEngine..ctor(String datapath, String language, EngineMode engineMode, IEnumerable`1 configFiles, IDictionary`2 initialOptions, Boolean setOnlyNonDebugVariables)
   at Tesseract.TesseractEngine..ctor(String datapath, String language, EngineMode engineMode)
   at SF_Demo.Views.盘口页面.登录() in C:\Users\Andun\Desktop\Worker-Now\Code\SF_Demo\Views\盘口页面.xaml.cs:line 584

  此异常最初是在此调用堆栈中引发的: 
    System.IO.Path.NormalizePath(string, bool, int, bool)
    System.IO.Path.InternalGetDirectoryName(string)
    InteropDotNet.LibraryLoader.CheckExecutingAssemblyDomain(string, string)
    InteropDotNet.LibraryLoader.LoadLibrary(string, string)
    InteropRuntimeImplementer.LeptonicaApiSignaturesInstance.LeptonicaApiSignaturesImplementation.LeptonicaApiSignaturesImplementation(InteropDotNet.LibraryLoader)

内部异常 1:
ArgumentException: 路径的形式不合法。

问题解决

方法1: 删除 Fody 即可

方法2: 在 FodyWeavers.xml 文件中添加

<Costura>
    <ExcludeAssemblies>
        Tesseract
    </ExcludeAssemblies>
</Costura>
最后修改:2025 年 03 月 24 日
如果觉得我的文章对你有用,请随意赞赏