Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# Access to the path denied on ubuntu 18.04 server

My friend and I wanted to make a discord server. I made the bot in c# and needed something to host it on so it can run 24/7, I've chosen Digitalocean. I created a ubuntu 18.04 droplet, installed dotnet sdk on it and cloned my github bot repo (Not the best solution, I know). But when I tried to do dotnet run, I got the "Access to path the path ' ' is denied" Error. I got the same error when i tried it using docker on ubuntu 16.04. Can anyone help me with this problem? (It worked fine on windows 10)

Dockerfile:

FROM microsoft/dotnet:2.1-sdk
WORKDIR /app

# copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# copy and build everything else
COPY . ./
RUN dotnet publish -c Release -o out
ENTRYPOINT ["dotnet", "out/Bot.dll"]

the error:

Unhandled Exception: System.UnauthorizedAccessException: Access to the path '/app/out' is denied. ---> System.IO.IOException: Permission denied
   --- End of inner exception stack trace ---
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at Bot.Program.MainAsync() in /app/Program.cs:line 38
   at Bot.Program.Main(String[] args) in /app/Program.cs:line 16

chmod -x and chmod -R 777 didn't work

like image 852
magiccheese Avatar asked Oct 17 '25 09:10

magiccheese


1 Answers

You have to make a release publish for ubuntu, give permission for execution with chmod -R 777 PATHTOPUBLISHFOLDER and then running it with path to the file without extension in the publish folder

like image 200
magiccheese Avatar answered Oct 20 '25 00:10

magiccheese



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!