Application.Restart throws InvalidOperationException
See original GitHub issue-
.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:
System.InvalidOperationException: Process was not started by this object, so requested information cannot be determined.
at System.Diagnostics.Process.get_StartInfo()
at System.Windows.Forms.Application.Restart()
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 under InitializeComponent in Form1), run it, and observe the exception.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:12 (12 by maintainers)
Top Results From Across the Web
c# - InvalidOperationException on Application.Exit
Do not call Application. · This is because you are trying to close the form in the closing event of it. · I...
Read more >FIX: You receive a System.InvalidOperationException ...
Fixes an issue in which an exception and an error message occur when you start a managed application that runs Extensible Object Markup...
Read more >Thread: [RESOLVED] Problems with Application.Restart()
I decided to add Application.Restart method into my program to enable restarting and applying new settings. After that I got the following ...
Read more >InvalidOperationException thrown after server restart
An unhandled exception might be thrown when the server restarts after ... The issue occurs only for the first request to the application...
Read more >Diagnosing an ASP.NET Core hard crash
The first of these causes an InvalidOperationException to be thrown. The second and third, between them, cause the app to crash. The debugger ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@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.
OMG, I just realized that we are using
Application.Restarttoo 😱 Another one obstruction on migrating process 😡 @EatonZ thank you very match for workaround!!!