Variables syntax

When I create variables for my app, do I have to surround the key and value with back ticks ``, as shown in this doc? https://docs.railway.app/reference/variables#template-syntax
Railway Docs
Variables | Railway Docs
Documentation for Railway
Solution:
So for anyone reading this I had to swap the two properties on either side of the "??" null-coalescing operator. For some reason the original first part _appSettings.TMDBSettings.BaseUrl , being local, should return null on Railway but somehow didn't. I assume it evaluated to something other than null, so the second part of the statement after the ?? was never evaluated. Swapping them allowed the Environment variable to be evaluated first, which returns null locally, but works on Railway since the Environment variable is evaluated first, and is successfully picked up on Railway by the app. var baseUrl = Environment.GetEnvironmentVariable("BaseUrl") ?? _appSettings.TMDBSettings.BaseUrl; At least that's my theory....
Jump to solution
19 Replies
Percy
Percyβ€’4mo ago
Project ID: N/A
Brody
Brodyβ€’4mo ago
no you don't, the backticks are inline codeblocks
David Bellerose
David Belleroseβ€’4mo ago
Ok, my asp.net app for some reason can't read my variables, It can read the DATABASE_URL ok, but for some reason it can't read the others. 14162ece-686d-4a9e-804f-1f26e3774377 Are you able to check to see if I entered them correctly? I double checked all the keys and values in the railway variables and in my app to make sure they match.
Brody
Brodyβ€’4mo ago
as im only a community mod i have zero access to your project, i would instead need to be shown screenshots and such
David Bellerose
David Belleroseβ€’4mo ago
Here is an example
No description
David Bellerose
David Belleroseβ€’4mo ago
My deployment log says that the BaseUrl is nul The syntax in my app to access the DATABASE_URL which works is the same to access the BaseUrl,
Brody
Brodyβ€’4mo ago
okay, lets see the code side of things where you try to access BaseUrl
David Bellerose
David Belleroseβ€’4mo ago
var baseUrl = _appSettings.TMDBSettings.BaseUrl ?? Environment.GetEnvironmentVariable("BaseUrl"); and here is the DATABASE_URL var databaseUrl = Environment.GetEnvironmentVariable("DATABASE_URL"); And in another app I can access my email settings ok var host = _mailSettings.MailHost ?? Environment.GetEnvironmentVariable("MailHost");
Brody
Brodyβ€’4mo ago
and what error do you get
David Bellerose
David Belleroseβ€’4mo ago
Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1] An unhandled exception has occurred while executing the request. System.NullReferenceException: Object reference not set to an instance of an object. at MoviePro.Services.TMDBMovieService.SearchMoviesAsync(MovieCategory category, Int32 count) in /app/Services/TMDBMovieService.cs:line 110
Brody
Brodyβ€’4mo ago
those errors seem unrelated?
David Bellerose
David Belleroseβ€’4mo ago
line 110 is the line I posted above for the BaseUrl, can you tell me how it is unrelated? I guess I misunterstood the error
Brody
Brodyβ€’4mo ago
the error mentioned an int32 but environment variables are strings, this would be a code or config issue
David Bellerose
David Belleroseβ€’4mo ago
Ah ok I missed that, sorry about that and thanks for pointing that out. πŸ™‚ So the int32 is the count of records to retrieve from the api, and the debugger shows that it is passing into the method correctly, it is not a variable set in the Railway app. From what I can tell the lines of code I posted above, the BaseUrl for example is set as a string. So I'm still thinking that the app can't see the Railway variable for some reason My app api works locally, but not on Railway
Brody
Brodyβ€’4mo ago
are you using a dockerfile?
David Bellerose
David Belleroseβ€’4mo ago
I don't believe so, It is .net mvc 6, I haven't had a need to create a docker file for my .net 6 apps. I did for my .net 8 blazor apps though. I commented out this part in the line 110 I posted above just to test if the "??" part of the line isn't working. Redeploying now. I'll post the result in a few minutes /*_appSettings.TMDBSettings.BaseUrl ??*/ lol that worked. I can see the api now. I'll make the adjustments to my code. Thanks for all your support and time. much appreciated
Brody
Brodyβ€’4mo ago
no problem, glad you were able to solve!
Solution
David Bellerose
David Belleroseβ€’4mo ago
So for anyone reading this I had to swap the two properties on either side of the "??" null-coalescing operator. For some reason the original first part _appSettings.TMDBSettings.BaseUrl , being local, should return null on Railway but somehow didn't. I assume it evaluated to something other than null, so the second part of the statement after the ?? was never evaluated. Swapping them allowed the Environment variable to be evaluated first, which returns null locally, but works on Railway since the Environment variable is evaluated first, and is successfully picked up on Railway by the app. var baseUrl = Environment.GetEnvironmentVariable("BaseUrl") ?? _appSettings.TMDBSettings.BaseUrl; At least that's my theory.
Brody
Brodyβ€’4mo ago
thanks for the follow-up!
Want results from more Discord servers?
Add your server