2

I’m trying to get my application running in a Docker container. Now I have a problem with file paths that are generated by dotnet core.

I changed my file paths according to this entry: Cross-platform file name handling in .NET Core

The output from dotnet core is the following for the path: /app/\foo/bar.txt (This throws a ‘Could not find part of the path’ exeption.)

If I hard code the path like this, it works: /app/foo/bar.txt

What can I change to get it working on Linux and Windows?

Shamshiel
  • 2,051
  • 3
  • 31
  • 50
  • How do you generate your paths? I never hit this problem. I – Christian Sauer May 28 '18 at 10:56
  • For example like this: System.IO.Path.Combine(PlatformServices.Default.Application.ApplicationBasePath.TrimEnd('\\')), @"\foo\", @"bar.txt"); This outputs ' /app/\foo/bar.txt' – Shamshiel May 28 '18 at 11:00
  • Can you just drop the "\" characters around foo, they cause the problems. If you cannot do this, there is Path.FullPath Method which should normalize all chars – Christian Sauer May 28 '18 at 11:02
  • But for example what happens if @"\foo\" would look like this @"\foo\too\moo\"? I can't just drop the "\" characters in this case. I will try the Path.FullPath Method. – Shamshiel May 28 '18 at 11:07
  • Hi, have you resolved the issue somehow? – M G Jan 11 '19 at 12:26
  • 1
    @MG I fixed it with the following code "filePath.Replace('\\', Path.DirectorySeparatorChar);" – Shamshiel Jan 14 '19 at 07:30
  • /app/foo/bar.txt should work on both windows and linux. It works for me. – Alpesh Aug 17 '20 at 16:24

0 Answers0