Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get startup parameters when windows service starts #9777

Closed
vicq23 opened this issue Apr 26, 2019 · 8 comments
Closed

Unable to get startup parameters when windows service starts #9777

vicq23 opened this issue Apr 26, 2019 · 8 comments
Labels
area-hosting Includes Hosting area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Comments

@vicq23
Copy link

vicq23 commented Apr 26, 2019

If you believe you have an issue that affects the security of the platform please do NOT create an issue and instead email your issue details to secure@microsoft.com. Your report may be eligible for our bug bounty but ONLY if it is reported through email.

Describe the bug

A clear and concise description of what the bug is.
After deploying the asp.net core project as a windows service, I started the project with (Get-Service "ServiceName").Start(@("--tag=dev")), but the args parameter in the Program.Main method is not. Get "--tag=dev", what is the reason?

To Reproduce

Steps to reproduce the behavior:

  1. Using this version of ASP.NET Core '...'
  2. Run this code '....'
  3. With these arguments '....'
  4. See error

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.
Include the output of dotnet --info

@davidfowl
Copy link
Member

Arguments aren't supported, this isn't something that works with the current windows service support.

@okman523 Can you fill in the other information please? Like version information?

cc @glennc @Tratcher

@glennc
Copy link
Contributor

glennc commented Apr 26, 2019

How are you verifying that you don't get the args in Program.Main?

@davidfowl
Copy link
Member

I believe OnStart has args. They don’t get passed into main

@Tratcher
Copy link
Member

So it does:
https://github.com/aspnet/Extensions/blob/1112d7bcb46fb5848f29a84cb3f906f75c07c8bc/src/Hosting/WindowsServices/src/WindowsServiceLifetime.cs#L64
The trouble is that we've already built and 'started' the app, it's just paused waiting for the go signal. At best you could give some kind of reloadable config provider, but most components don't check for config changes.

@vicq23
Copy link
Author

vicq23 commented Apr 27, 2019

@davidfowl I need to get the command line parameters in Main, as the parameters needed for the program initialization, it is too late to get the parameters in OnStart, it means nothing to me.

@vicq23
Copy link
Author

vicq23 commented Apr 27, 2019

@Tratcher Yes, this is not reasonable, it is right to get the parameters when the program starts.

@Tratcher
Copy link
Member

Here's an interesting thread:
https://stackoverflow.com/questions/1488851/how-to-pass-a-parameter-to-a-windows-service-once-and-for-all-at-install-instead

There are two places to put parameters:

  1. In the image path: myapp.exe options. These get passed to Main
  2. In StartService, these get passed to ServiceBase.OnStart.

There's nothing for us to do here, this is just how Windows Services work. Can you try the image path approach?

@analogrelay
Copy link
Contributor

Closing this as we haven't heard from you and generally close issues with no response after ~7 days. Please feel free to comment if you're able to get the information we're looking for and we can reopen the issue to investigate further!

@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
@amcasey amcasey added the area-hosting Includes Hosting label Jun 1, 2023
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-hosting Includes Hosting area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

No branches or pull requests

8 participants