Project won't deploy

samson
HOBBY

3 months ago

Hello guys,
I'm completely new to this hosting stuff and I'm trying to host a discord bot that I used to start locally from VS Studio before.
I hooked up my github and try to deploy the container.

Id: 24415e1c-9ff5-4133-b834-05af53c29590

Build suceeds but deploy crashes with following message:

Unhandled exception. System.TypeLoadException: Could not load type System.Runtime.CompilerServices.NullableContextAttribute from assembly System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. at System.ModuleHandle.ResolveType(QCallModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) at System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport&amp; scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1&amp; derivedAttributes, RuntimeType&amp; attributeType, IRuntimeMethodInfo&amp; ctorWithParameters, Boolean&amp; isVarArg) at System.Reflection.CustomAttribute.IsCustomAttributeDefined(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Int32 attributeCtorToken, Boolean mustBeInheritable) at System.Reflection.CustomAttribute.IsDefined(RuntimeType type, RuntimeType caType, Boolean inherit) at System.Diagnostics.StackTrace.ToString(TraceFormat traceFormat, StringBuilder sb) at System.Diagnostics.StackTrace.ToString(TraceFormat traceFormat) at System.Exception.get_StackTrace() at System.Exception.ToString() at Program.Main(String[] args) in /app/SubBot/Program.cs:line 44 at Program.<main>(String[] args)

Solved

0 Replies

samson
HOBBY

3 months ago

Project won't deploy


yellowmacaroni
PRO

3 months ago

Are you using nixpacks or a Dockerfile?


yellowmacaroni
PRO

3 months ago

It looks like you are running a .NET 8.0 project on the wrong version (.NET 6.0?)


samson
HOBBY

3 months ago

I do have a docker file but I saw it building with nix packs


samson
HOBBY

3 months ago

That's the build log.

Region: europe-west4]

Using Nixpacks

context: rpk8-2czM
╔═════════════════════ Nixpacks v1.34.1 ═════════════════════╗
║ setup │ dotnet-sdk_8 ║
║────────────────────────────────────────────────────────────║
║ install │ dotnet restore ║
║────────────────────────────────────────────────────────────║
║ build │ dotnet publish --no-restore -c Release -o out ║
║────────────────────────────────────────────────────────────║
║ start │ ./out/SubBot ║
╚════════════════════════════════════════════════════════════╝
[internal] load build definition from Dockerfile
[internal] load build definition from Dockerfile ✔ 0ms
[internal] load build definition from Dockerfile
[internal] load build definition from Dockerfile ✔ 10ms
[internal] load metadata for ghcr.io/railwayapp/nixpacks:ubuntu-1741046653
[internal] load metadata for ghcr.io/railwayapp/nixpacks:ubuntu-1741046653 ✔ 149ms
[internal] load .dockerignore
[internal] load .dockerignore
[internal] load .dockerignore ✔ 0ms
[internal] load .dockerignore
[internal] load .dockerignore ✔ 11ms
[internal] load build context ✔ 0ms
[internal] load build context
[internal] load build context ✔ 637ms
[3/9] COPY .nixpacks/nixpkgs-5148520bfab61f99fd25fb9ff7bfbb50dad3c9db.nix .nixpacks/nixpkgs-5148520bfab61f99fd25fb9ff7bfbb50dad3c9db.nix ✔ 0ms – CACHED
[4/9] RUN nix-env -if .nixpacks/nixpkgs-5148520bfab61f99fd25fb9ff7bfbb50dad3c9db.nix && nix-collect-garbage -d ✔ 0ms – CACHED
[5/9] COPY . /app/.
[5/9] COPY . /app/. ✔ 154ms
[6/9] RUN dotnet restore

Welcome to .NET 8.0!

SDK Version: 8.0.100-preview.5.23303.2


yellowmacaroni
PRO

3 months ago

set the ENV NIXPACKSCSHARPSDK_VERSION=8.0.311


yellowmacaroni
PRO

3 months ago

It shouldnt use Nixpacks if you have a dockerfile though


yellowmacaroni
PRO

3 months ago

This is my Dockerfile, make sure its in your base directory (of your github repo)

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /app

# Copy and restore dependencies
COPY . .
RUN dotnet restore

# Publish the application
RUN dotnet publish -c Release -o /out

# Use a lightweight runtime image
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /out .

# Set the entry point
ENTRYPOINT ["dotnet", "Discord Bot.dll"]

samson
HOBBY

3 months ago

This is mine:

`# Build-Phase mit SDK
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["SubBot/SubBot.csproj", "SubBot/"]
COPY . .
WORKDIR "/src/SubBot"
RUN dotnet publish "SubBot.csproj" -c Release -r linux-x64 --self-contained true -o /app/publish /p:PublishSingleFile=true /p:PublishTrimmed=false

Minimaler Runtime-Container – ohne dotnet runtime

FROM debian:bullseye-slim AS final
WORKDIR /app
COPY --from=build /app/publish .
RUN chmod +x SubBot
ENTRYPOINT ["./SubBot"]`

1363935138869940700


samson
HOBBY

3 months ago

and it lies here

1363935162437599500


yellowmacaroni
PRO

3 months ago

Is that the base directory for your repo? For mine, I have the Dockerfile in the solution directory.

1363935578369819000


samson
HOBBY

3 months ago

This is at the top

1363935798352810200


samson
HOBBY

3 months ago

should i place it there?


yellowmacaroni
PRO

3 months ago

Yes, that is the git repo's base directory since it has the .git folder in it


samson
HOBBY

3 months ago

Sorry, i feel utterly dumb asking this questions…


yellowmacaroni
PRO

3 months ago

Nah its fine


samson
HOBBY

3 months ago

now im getting this error:
✕ [build 6/6] RUN dotnet publish "SubBot.csproj" -c Release -r linux-x64 --self-contained true -o /app/publish /p:PublishSingleFile=true /p:PublishTrimmed=false
process "/bin/sh -c dotnet publish \"SubBot.csproj\" -c Release -r linux-x64 --self-contained true -o /app/publish /p:PublishSingleFile=true /p:PublishTrimmed=false" did not complete successfully: exit code: 145


samson
HOBBY

3 months ago

`The command could not be loaded, possibly because:

  • You intended to execute a .NET application:
    The application 'publish' does not exist.

  • You intended to execute a .NET SDK command:
    A compatible .NET SDK was not found.
    Requested SDK version: 8.0.100
    global.json file: /src/SubBot/global.json
    Installed SDKs:
    Install the [8.0.100] .NET SDK or update [/src/SubBot/global.json] to match an installed SDK.
    Learn about SDK resolution:
    [https://aka.ms/dotnet/sdk-not-found](https://aka.ms/dotnet/sdk-not-found)


yellowmacaroni
PRO

3 months ago

I believe you just need to change all of the SubBot.csproj instances with ./SubBot.csproj


yellowmacaroni
PRO

3 months ago

Since you moved the Dockerfile to a different directory


samson
HOBBY

3 months ago

in my dockerfile aight?


yellowmacaroni
PRO

3 months ago

Yes


yellowmacaroni
PRO

3 months ago

should look like that

1363937355127456000


samson
HOBBY

3 months ago

i changed my dockerfile to this self containing thing. should i try yours and change the names obviously?


yellowmacaroni
PRO

3 months ago

Wait sorry it should be ./SubBot/SubBot.csproj


yellowmacaroni
PRO

3 months ago

Uh


yellowmacaroni
PRO

3 months ago

Yeah one sec


yellowmacaroni
PRO

3 months ago

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /app

# Copy and restore dependencies
COPY . .
RUN dotnet restore

# Publish the application
RUN dotnet publish -c Release -o /out

# Use a lightweight runtime image
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /out .

# Set the entry point
ENTRYPOINT ["dotnet", "Discord Bot.dll"]

yellowmacaroni
PRO

3 months ago

This is a pretty bare bones one


yellowmacaroni
PRO

3 months ago

# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

# This stage is used when running from VS in fast mode (Default for Debug configuration)
FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base
USER $APP_UID
WORKDIR /app


# This stage is used to build the service project
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Whispbot.csproj", "."]
RUN dotnet restore "./Whispbot.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "./Whispbot.csproj" -c $BUILD_CONFIGURATION -o /app/build

# This stage is used to publish the service project to be copied to the final stage
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Whispbot.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Whispbot.dll"]

This is the official visual studio one


yellowmacaroni
PRO

3 months ago

I have my project and solution in the same directory so you would have to change the stuff around slightly


samson
HOBBY

3 months ago

oh boi


samson
HOBBY

3 months ago

then im trying that offical one


yellowmacaroni
PRO

3 months ago

When I created my newest project, I set it up to use the dockerfile by default


samson
HOBBY

3 months ago

on railway?


yellowmacaroni
PRO

3 months ago

On visual studio


yellowmacaroni
PRO

3 months ago

I dont think you can change it now


yellowmacaroni
PRO

3 months ago

But ill generate a dockerfile for you


samson
HOBBY

3 months ago

`# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

This stage is used when running from VS in fast mode (Default for Debug configuration)

FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base
USER $APP_UID
WORKDIR /app

This stage is used to build the service project

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILDCONFIGURATION=Release WORKDIR /src COPY ["SubBot/SubBot.csproj", "SubBot/"] RUN dotnet restore "SubBot/SubBot.csproj" COPY . . WORKDIR "/src/SubBot" RUN dotnet build "./SubBot.csproj" -c $BUILDCONFIGURATION -o /app/build

This stage is used to publish the service project to be copied to the final stage

FROM build AS publish
ARG BUILDCONFIGURATION=Release RUN dotnet publish "./SubBot.csproj" -c $BUILDCONFIGURATION -o /app/publish /p:UseAppHost=false

This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["./SubBot", "SubBot.dll"]`

i haave this now


yellowmacaroni
PRO

3 months ago

I would assume that would work if you change the RUN dotnet line to have "./SubBot/SubBot.csproj" and the entrypoint to be ["dotnet", "SubBot.dll"]


samson
HOBBY

3 months ago

why dotnet?


yellowmacaroni
PRO

3 months ago

Dotnet = .NET


samson
HOBBY

3 months ago

```# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

This stage is used when running from VS in fast mode (Default for Debug configuration)

FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base
USER $APP_UID
WORKDIR /app

This stage is used to build the service project

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILDCONFIGURATION=Release WORKDIR /src COPY ["SubBot/SubBot.csproj", "SubBot/"] RUN dotnet restore "SubBot/SubBot.csproj" COPY . . WORKDIR "/src/SubBot" RUN dotnet build "./SubBot/SubBot.csproj" -c $BUILDCONFIGURATION -o /app/build

This stage is used to publish the service project to be copied to the final stage

FROM build AS publish
ARG BUILDCONFIGURATION=Release RUN dotnet publish "./SubBot/SubBot.csproj" -c $BUILDCONFIGURATION -o /app/publish /p:UseAppHost=false

This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "SubBot.dll"]```

looks like this now


yellowmacaroni
PRO

3 months ago

Its the CLI for c#


yellowmacaroni
PRO

3 months ago

That looks correct


samson
HOBBY

3 months ago

pushing it.


samson
HOBBY

3 months ago

i mean i have no clue what those lines excatly do 😄 so yea…


samson
HOBBY

3 months ago

The command could not be loaded, possibly because:

  • You intended to execute a .NET application:
    The application 'build' does not exist.

  • You intended to execute a .NET SDK command:
    A compatible .NET SDK was not found.

Requested SDK version: 8.0.100
global.json file: /src/SubBot/global.json

Installed SDKs:

Install the [8.0.100] .NET SDK or update [/src/SubBot/global.json] to match an installed SDK.

Learn about SDK resolution:
https://aka.ms/dotnet/sdk-not-found


samson
HOBBY

3 months ago

should i remove the global.json?


yellowmacaroni
PRO

3 months ago

yeah


yellowmacaroni
PRO

3 months ago

its interfering with it


samson
HOBBY

3 months ago

`MSBUILD : error MSB1009: Project file does not exist.
Switch: ./SubBot/SubBot.csproj
✕ [build 7/7] RUN dotnet build "./SubBot/SubBot.csproj" -c Release -o /app/build
process "/bin/sh -c dotnet build \"./SubBot/SubBot.csproj\" -c $BUILD_CONFIGURATION -o /app/build" did not complete successfully: exit code: 1

Dockerfile:16

14 | COPY . .
15 | WORKDIR "/src/SubBot"
16 | >>> RUN dotnet build "./SubBot/SubBot.csproj" -c $BUILD_CONFIGURATION -o /app/build
17 |

18 | # This stage is used to publish the service project to be copied to the final stage

ERROR: failed to solve: process "/bin/sh -c dotnet build \"./SubBot/SubBot.csproj\" -c $BUILD_CONFIGURATION -o /app/build" did not complete successfully: exit code: 1`

<:KEKW:947842215005286460>

oh boi i guess its a path thing


yellowmacaroni
PRO

3 months ago

uhhhhhhhhhhhhhhhhh


samson
HOBBY

3 months ago

yea 😄


yellowmacaroni
PRO

3 months ago

Oh okay im stupid


samson
HOBBY

3 months ago

No


samson
HOBBY

3 months ago

IM stupid!


yellowmacaroni
PRO

3 months ago

RUN dotnet build "SubBot.csproj"


yellowmacaroni
PRO

3 months ago

do that


yellowmacaroni
PRO

3 months ago

I told you to change that one


samson
HOBBY

3 months ago

publish aswell?


yellowmacaroni
PRO

3 months ago

and the same with publish


samson
HOBBY

3 months ago

yea


samson
HOBBY

3 months ago

it's taking longer now


samson
HOBBY

3 months ago

ahh


samson
HOBBY

3 months ago

its active but crashed


samson
HOBBY

3 months ago

The configuration file 'appsettings.json' was not found and is not optional. The expected physical path was '/app/appsettings.json'.

need to replace the config logic with the enviroment logic from raailway for tokens i guess


yellowmacaroni
PRO

3 months ago

Or you can put it in a volume


yellowmacaroni
PRO

3 months ago

But for tokens definitely use ENV


samson
HOBBY

3 months ago

Do i place them into the service variables or shared variables?


yellowmacaroni
PRO

3 months ago

service unless you are using the token across multiple services which is unlikely (e.g. you have a main bot and an seperate API service)


yellowmacaroni
PRO

3 months ago

if you arent planning on using ENVs on more than one service then use the service variables


samson
HOBBY

3 months ago

nah its just a simple bot for registering substitute players.
i need to connect a database now.
That was the reason to try railway because i didnt want to host a db myself locally


samson
HOBBY

3 months ago

Do you have a .net bot with dsharpplus as well?


yellowmacaroni
PRO

3 months ago

i created a custom discord api wrapper package for my bots


yellowmacaroni
PRO

3 months ago

i dont use any packages


samson
HOBBY

3 months ago

Ah, okay nice.
And if I read thatr correctly i log to Console.WriteLine(); to see it in Railway?


yellowmacaroni
PRO

3 months ago

Yes


samson
HOBBY

3 months ago

ah and your were a huuuuuuuuge help!!!


samson
HOBBY

3 months ago

Thank you so much!


yellowmacaroni
PRO

3 months ago

I was bored


yellowmacaroni
PRO

3 months ago

No problem


samson
HOBBY

3 months ago

Best thing that could happen


yellowmacaroni
PRO

3 months ago

very


samson
HOBBY

3 months ago

is it possible to run an sql file to fill a database here?


yellowmacaroni
PRO

3 months ago

ive never tried it


yellowmacaroni
PRO

3 months ago

you could probably use an external program like tableplus to run SQL queries on the database


samson
HOBBY

3 months ago

Ah yea, i can connect to the db from my computer and run it there. im using heidisql


samson
HOBBY

3 months ago

that should work


yellowmacaroni
PRO

3 months ago

yeah that should work


yellowmacaroni
PRO

3 months ago

the database should have a public and a private url


yellowmacaroni
PRO

3 months ago

use public to connect to it externally and the private to connect to it on your main program when running on railway (to save on egress costs)


samson
HOBBY

3 months ago

postgresql://postgres:@metro.proxy.rlwy.net:42005/railway

Like this?


yellowmacaroni
PRO

3 months ago

yes


yellowmacaroni
PRO

3 months ago

that should be the public one


samson
HOBBY

3 months ago

the internal one is just a variable

${{ Postgres.DATABASE_URL }}


yellowmacaroni
PRO

3 months ago

Yup


samson
HOBBY

3 months ago

oops i just saw i used mysql back then 😄
Reviving the bot atm 😄


samson
HOBBY

3 months ago

_connectionString = enviroment.mysql.DATABASE_URL; MySqlConnection connection = new MySqlConnection(_connectionString); try { await connection.OpenAsync(); Console.WriteLine("Die Verbindung zur HL-Datenbank wurde erfolgreich geöffnet."); return connection; } catch (Exception ex) { Console.WriteLine("Fehler beim Öffnen der Verbindung zur HL-Datenbank: " + ex.Message); return new MySqlConnection(); }

that would be my guess to connect internally


yellowmacaroni
PRO

3 months ago

Yes, Is environment a custom class or?


yellowmacaroni
PRO

3 months ago

it should be

Environment.GetEnvironmentVariable("DATABASE_URL")

samson
HOBBY

3 months ago

ah yeas. i meant that 😄


samson
HOBBY

3 months ago

do i have to insert the databse variables into my service variables or are they "gobally" by default?


yellowmacaroni
PRO

3 months ago

you would have to insert them


yellowmacaroni
PRO

3 months ago

${{MySql.DATABASE_URL}}


yellowmacaroni
PRO

3 months ago

Or whatever


samson
HOBBY

3 months ago

ahhh now i see the connection

1363948659426857200


samson
HOBBY

3 months ago

Thank you!!!

1363950063730167800


samson
HOBBY

3 months ago

How do you debug your bot when its running on railway?
Is it the old write logs, deploy and repeat thing? 😄


yellowmacaroni
PRO

3 months ago

ofcourse

1363950685242130400


samson
HOBBY

3 months ago

love that <:KEKW:947842215005286460>


samson
HOBBY

3 months ago

im used to it


samson
HOBBY

3 months ago

oh bro thanks again


yellowmacaroni
PRO

3 months ago

no problem!


3 months ago

relatable


3 months ago

looks like we’re good to call this solved?


yellowmacaroni
PRO

3 months ago

Yup


3 months ago

!s


Status changed to Solved adam 3 months ago