a year ago
Hello,
I am trying to get the following files referenced like so in my C# code:
private static readonly HashSet validWords = new(
File.ReadLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "commands/wordle-group/helpers/wordlist.txt"))
);
private static readonly HashSet possibleAnswers = new(
File.ReadLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "commands/wordle-group/helpers/answerlist.txt"))
);It works on my Windows PC, but not on Railway, I tried adding this to my .csproj:
PreserveNewest
PreserveNewestbut that didnt work, so I then tried doing this to my .docker:
COPY ./commands/wordle-group/helpers/wordlist.txt /app/commands/wordle-group/helpers/wordlist.txt
COPY ./commands/wordle-group/helpers/answerlist.txt /app/commands/wordle-group/helpers/answerlist.txtThis also did not work. Any ideas?
28 Replies
a year ago
048dcb13-17c0-49e6-a509-420f8098afe8
a year ago
what error are you getting?
a year ago
---> System.TypeInitializationException: The type initializer for 'Commands.Helpers.WordleMethods' threw an exception.
---> System.IO.FileNotFoundException: Could not find file '/app/commands/wordle-group/helpers/wordlist.txt'.
File name: '/app/commands/wordle-group/helpers/wordlist.txt'
at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter)
at Interop.CheckIo(Error error, String path, Boolean isDirectory, Func`2 errorRewriter)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
at System.IO.Strategies.FileStreamHelpers.ChooseStrategy(FileStream fileStream, String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize)
at System.IO.StreamReader.ValidateArgsAndOpenPath(String path, Encoding encoding, Int32 bufferSize)
at System.IO.File.ReadLines(String path)
at Commands.Helpers.WordleMethods..cctor() in /app/commands/wordle-group/helpers/wordleMethods.cs:line 15
--- End of inner exception stack trace ---
at Commands.Helpers.WordleMethods.GetRandomWord() in /app/commands/wordle-group/helpers/wordleMethods.cs:line 73
at Commands.Helpers.Wordle.StartBotGame(SocketInteraction interaction) in /app/commands/wordle-group/helpers/wordleGame.cs:line 43
at Commands.WordleGroup.NewGame() in /app/commands/wordle-group/wordleCommands.cs:line 30
at Discord.Interactions.Builders.ModuleClassBuilder.<>c__DisplayClass11_0.<g__ExecuteCallback|1>d.MoveNext()
--- End of inner exception stack trace ---a year ago
so, highlights:
---> System.IO.FileNotFoundException: Could not find file '/app/commands/wordle-group/helpers/wordlist.txt'.a year ago
Send your full Dockerfile please
a year ago
# Use the official .NET image as a base image for building the app
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
# Set the working directory inside the container
WORKDIR /app
# Copy the .csproj files and restore dependencies
COPY *.csproj ./
RUN dotnet restore
# Copy the rest of the application source code into the container
COPY . ./
# Build the application in Release configuration and output to the /out directory
RUN dotnet publish -c Release -o out
# Use a runtime-only .NET image for the final image (smaller size)
FROM mcr.microsoft.com/dotnet/runtime:6.0
# Install necessary Linux packages (for fonts and graphical capabilities)
RUN apt-get update && \
apt-get install -y libharfbuzz0b libfontconfig1 libfreetype6 libgl1-mesa-dev libglu1-mesa && \
rm -rf /var/lib/apt/lists/*
# Set the working directory inside the final container
WORKDIR /app
# Copy the wordlist and answerlist files into the container (ensure paths are correct)
# These files must exist in the build context (the directory you're running `docker build` from)
COPY ./commands/wordle-group/helpers/wordlist.txt /app/commands/wordle-group/helpers/wordlist.txt
COPY ./commands/wordle-group/helpers/answerlist.txt /app/commands/wordle-group/helpers/answerlist.txt
# Copy the output of the build from the previous stage
COPY --from=build /app/out .
# Set the entry point for the application
ENTRYPOINT ["dotnet", "main.dll"]a year ago
the docker changes I made:
# Copy the wordlist and answerlist files into the container (ensure paths are correct)
# These files must exist in the build context (the directory you're running `docker build` from)
COPY ./commands/wordle-group/helpers/wordlist.txt /app/commands/wordle-group/helpers/wordlist.txt
COPY ./commands/wordle-group/helpers/answerlist.txt /app/commands/wordle-group/helpers/answerlist.txtwere (obviously) written by chatgpt
a year ago
hmmm
a year ago
oh wait
a year ago
-----
> [stage-1 4/6] COPY ./commands/wordle-group/helpers/wordlist.txt /app/commands/wordle-group/helpers/wordlist.txt:
-----
-----
> [stage-1 5/6] COPY ./commands/wordle-group/helpers/answerlist.txt /app/commands/wordle-group/helpers/answerlist.txt:
-----
Dockerfile:30
-------------------
28 | # Copy the wordlist for Wordle
29 | COPY ./commands/wordle-group/helpers/wordlist.txt /app/commands/wordle-group/helpers/wordlist.txt
30 | >>> COPY ./commands/wordle-group/helpers/answerlist.txt /app/commands/wordle-group/helpers/answerlist.txt
31 |
32 | # Copy the built application from the build stage
-------------------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref pd5rgqrxmf9bi8kx9cd7a3fsx::t2wxztcstik2fhzt0uxcjfv91: "/commands/wordle-group/helpers/answerlist.txt": not founda year ago
build logs
a year ago
I forgot how many different trials of this I have had…
a year ago
wordlist indeed does not exist at that location in the current active deploy
a year ago
is the repo
a year ago
# cat /app/commands/wordle-group/helpers/wordlist.txt
cat: /app/commands/wordle-group/helpers/wordlist.txt: No such file or directorya year ago
what is that
a year ago
a shell output
a year ago
ah ok
a year ago
well, the current deploy got the C# error I sent, the failed most recent deploy got the docker error I sent
a year ago
oh dear…
a year ago
is it the capital L
a year ago
```# pwd
/app/commands/wordle-group/helpers
ls
answerList.txt wordList.txt```
a year ago
yep
a year ago
😦
a year ago
thanks very much
a year ago
no problem!
a year ago
!s
Status changed to Solved brody • about 1 year ago