I’m having trouble with my Telegram bot built using ASP.NET Core 3.1 and C#. The bot uses webhooks and I’m testing it with ngrok for local development.
When I start the project directly from Visual Studio, everything works perfectly. The bot responds to all commands correctly and ngrok shows 200 OK status codes.
However, when I try to run the compiled executable file (either debug or release build) from the output folder, the bot stops working completely. Instead of getting successful responses, ngrok returns 502 bad gateway errors.
Has anyone encountered this issue before? What might be causing the difference in behavior between running from VS versus the standalone executable?
I’ve faced a similar situation with my ASP.NET Core bot. When running from Visual Studio, it sets up the environment in a way that might not be replicated when you execute the standalone .exe. A common issue is related to file paths or environment variables not being recognized. To troubleshoot, ensure the executable is being run in the correct directory where your appsettings.json is located. Additionally, verify if there are any hardcoded configurations that may differ in the production environment compared to your development setup.
This is definitely a port binding issue - super common with ASP.NET Core apps. Visual Studio handles port config automatically through launchSettings.json, but your standalone exe might be binding to localhost only or using different port settings. Check your Program.cs or Startup.cs for hardcoded URLs that work in dev but break in production. Try running your exe with explicit URL binding: yourapp.exe --urls=http://localhost:5000. Also double-check that ngrok is pointing to the same port your app is actually listening on - port mismatches cause 502 errors all the time.
yep, classic environment setup issue. VS loads all the stuff automatically, but your exe might be missin required DLLs. check if the output folder has all necessary files. also, make sure your webhook URL is correct in the exe - it might use diff default settings than VS.