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

fix: Application.Restart throws InvalidOperationException #2845

Merged
merged 2 commits into from
May 21, 2020
Merged

fix: Application.Restart throws InvalidOperationException #2845

merged 2 commits into from
May 21, 2020

Conversation

EatonZ
Copy link
Contributor

@EatonZ EatonZ commented Feb 12, 2020

Fixes #2769

Proposed changes

Implemented the suggested fix from @stephentoub.

Customer Impact

This fixes a method broken by changes in .NET Core. Most customers are probably unaware of the broken method since it is not a documented breaking change, nor are there other issues reporting the breakage.

Regression?

  • Yes

Risk

There should be no risk. I have tested this fix myself and confirmed that it works.

Microsoft Reviewers: Open in CodeFlow

@EatonZ EatonZ requested a review from a team as a code owner February 12, 2020 02:16
@ghost ghost assigned EatonZ Feb 12, 2020
@@ -1167,7 +1167,7 @@ public static void Restart()
sb.Append(arguments[arguments.Length - 1]);
sb.Append('"');
}
ProcessStartInfo currentStartInfo = Process.GetCurrentProcess().StartInfo;
ProcessStartInfo currentStartInfo = new ProcessStartInfo();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a test we can add?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this method is unit-testable, there are too many moving parts here. Can't think of a relatively low-effort automation either, we haven't done any automated integration tests yet...
However I do agree we some form a verification that it is working as intended.

@EatonZ please have a look at #2801. I have created few PS scripts that generate net472 and netcoreapp5.0 app, and then ran manual tests against them to confirm the fix.
You could tweak the "single app" script and then run a series of tests with and without input parameters.

A verification would be something along the lines of:

# build and run the app, passing parameters to it
dotnet run -- a b c
# app restarted, confirm parameters
Get-WmiObject Win32_Process | where name -eq your_app_name.exe | select commandline

@hughbe any thoughts on how else we can test this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RussKie It seems like we could use the scripts you made there, with 1 tweak: replace => System.Windows.Forms.Application.ExecutablePath; with => System.Windows.Forms.Application.Restart();, wrap that in a try/catch and report a failed test if it throws an exception.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We still need to confirm all input arguments are being passed to the new instance.

@codecov
Copy link

codecov bot commented Feb 12, 2020

Codecov Report

Merging #2845 into master will increase coverage by 0.00883%.
The diff coverage is n/a.

@@                 Coverage Diff                 @@
##              master       #2845         +/-   ##
===================================================
+ Coverage   59.52728%   59.53611%   +0.00883%     
===================================================
  Files           1236        1236                 
  Lines         429934      429934                 
  Branches       38787       38787                 
===================================================
+ Hits          255928      255966         +38     
+ Misses        168636      168590         -46     
- Partials        5370        5378          +8     
Flag Coverage Δ
#Debug 59.53611% <0.00000%> (+0.00883%) ⬆️
#production 32.22643% <0.00000%> (+0.01496%) ⬆️
#test 98.96829% <ø> (ø) ⬆️

@RussKie RussKie added the waiting-author-feedback The team requires more information from the author label Feb 12, 2020
@ghost ghost removed the waiting-author-feedback The team requires more information from the author label Feb 12, 2020
@RussKie
Copy link
Member

RussKie commented May 21, 2020

Sorry for the delay, it has slipped off my radar.
I've run tests locally, and confirmed the fix. Thank you 👍

@RussKie RussKie merged commit eaf006d into dotnet:master May 21, 2020
@ghost ghost added this to the 5.0 Preview6 milestone May 21, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Feb 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Application.Restart throws InvalidOperationException
3 participants