-
Notifications
You must be signed in to change notification settings - Fork 998
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
Application.Restart throws InvalidOperationException #2769
Comments
@danmosemsft @stephentoub @davkean for us this is a regression caused by a change introduced in dotnet/corefx#1167 Could you please provide guidance on how to restart the app? winforms/src/System.Windows.Forms/src/System/Windows/Forms/Application.cs Lines 1172 to 1195 in 62c17fe
|
Application.Restart and .NET Core 1.0 didn't exist at the time that change was checked in, so its not a regression. Probably need a bug against CoreFx to let you look at the StartInfo of a process if its the "current process". |
For us it is a regression because it worked in .NET Framework and it doesn't work in .NET Core. |
The only valid piece of Process.GetCurrentProcess().StartInfo was the environment variables, which are also populated when creating a new PSI. Just create a new PSI and populate it as you already are, e.g. replace: Process.GetCurrentProcess().StartInfo with new ProcessStartInfo() That's simpler and cheaper. |
Hi @merriemcgaw, is the fix really only going to make it for 5.0? |
I'm confident once it is fixed, it will be considered for a servicing in 3.1. As an interim workaround you could copy the implementation of winforms/src/System.Windows.Forms/src/System/Windows/Forms/Application.cs Lines 1173 to 1195 in 62c17fe
|
@RussKie I couldn't get it working when I tried before, but I tried again and this time I realized why. Turns out, there is a second bug in there, but that one is already being fixed, by you!😁 I modified the method a bit and it works fine now.
|
Btw you're welcome to send a PR with the fix 😉 |
@RussKie I wasn't sure if the proper fix was that simple... but I guess it is, so I just submitted a PR.😁 |
This particular bug, since it's not blocking you at the moment, doesn't meet the servicing bar for 3.1, but I am very glad you got it in for 5.0. If we find out that this is blocking someone and impacting customers then I believe it would meet the bar and we'd take it. But at this point the workaround is a viable one I'm afraid. |
Hi @merriemcgaw, I think it's a long time to wait until November for a 1-line fix. If that is what you want to do, then I suggest documenting this breakage somewhere so people will be able to find the workaround when searching. |
OMG, I just realized that we are using |
.NET Core Version:
3.1.1
Have you experienced this same bug with .NET Framework?:
No - this has always worked fine on .NET Framework!
Problem description:
Calling
Application.Restart
in a .NET Core WinForms application does not work as it does on .NET Framework. An exception is thrown:I also tried launching the exe without the debugger, but that doesn't make a difference.
Additionally, there is no note or breaking change detailing any .NET Core changes.
Expected behavior:
Application.Restart
should work the same as it does on .NET Framework.Minimal repro:
Create a new .NET Core WinForms project in Visual Studio, put
Application.Restart
anywhere (even underInitializeComponent
inForm1
), run it, and observe the exception.The text was updated successfully, but these errors were encountered: