传递给 File.ReadAllBytes 方法的文件路径被预先执行的路径覆盖

File path passed to File.ReadAllBytes method are overridden by prepending executing path

传递给 File.ReadAllBytes 方法的文件路径被预先执行的路径覆盖

这是控制台应用程序 运行 作为调试中使用 TopShelf 的服务。

var bytes = File.ReadAllBytes(@"‪‪d:\ubuntu-20.04.2.0-desktop-amd64.iso.torrent");

System.IO.IOException: 'The filename, directory name, or volume label syntax is incorrect. : 'C:\FR\src\Service\bin\Debug\net5.0\‪D:\ubuntu-20.04.2.0-desktop-amd64.iso.torrent

堆栈跟踪

at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.File.ReadAllBytes(String path)
at FR.Engine.Actors.FileReaderActor.OnReadFileCommand(FileReadCommand command) in C:\FR\src\FR.Engine\Actors\FileReaderActor.cs:line 18
at FR.Engine.Actors.FileReaderActor.<.ctor>b__0_0(FileReadCommand command) in C:\FR\src\FR.Engine\Actors\FileReaderActor.cs:line 11
at Akka.Tools.MatchHandler.PartialHandlerArgumentsCapture`2.Handle(T value)
at Akka.Actor.ReceiveActor.ExecutePartialMessageHandler(Object message, PartialAction`1 partialAction)
at Akka.Actor.ReceiveActor.OnReceive(Object message)
at Akka.Actor.UntypedActor.Receive(Object message)
at Akka.Actor.ActorBase.AroundReceive(Receive receive, Object message)
at Akka.Actor.ActorCell.ReceiveMessage(Object message)
at Akka.Actor.ActorCell.Invoke(Envelope envelope)

出于调试目的,我添加了一行 - 参考 snip 的值

var fullpath = Path.GetFullPath(command.Path);

它适用于带有 Topshelf 的简单 .net5 控制台应用程序。所以我怀疑是 Akka.net 造成的。

一些非标准字符(不可见)在您的字符串中的“d:”之前编码,这就是您有这种行为的原因。如果您手动重写您的路径(使用引号),它将起作用。

在此示例中,“filePathA”是您路径的复制粘贴,“filePathB”是我重写的路径。

filePathA = 51 字节

filePathB = 45 字节