dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.29k stars 956 forks source link

Re-occurrence of WinForms designer failing to load (was #8996) #11189

Open CCarneySIA opened 2 months ago

CCarneySIA commented 2 months ago

Environment

Microsoft Visual Studio Professional 2022 Version 17.8.6 VisualStudio.17.Release/17.8.6+34525.116 Microsoft .NET Framework Version 4.8.04084

Installed Version: Professional

C# Tools 4.8.0-7.23572.1+7b75981cf3bd520b86ec4ed00ec156c8bc48e4eb C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Microsoft Azure Tools for Visual Studio 2.9 Support for Azure Cloud Services projects

NuGet Package Manager 6.8.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Visual Basic Tools 4.8.0-7.23572.1+7b75981cf3bd520b86ec4ed00ec156c8bc48e4eb Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio.

Windows 10 Pro, Version 21H2, Installed 11/9/2022, build # 19044.3086.

.NET version

.NET 8.0 (just updated today 4/9/2024)

Did this work in a previous version of Visual Studio and/or previous .NET release?

No... first project targeting .NET 8

Issue description

This is an exact copy of the issue #8996. Same behavior (exception prevents designer form loading on creation of any .NET 6.0 or 8.0 project), same error messages (every character!), and I was able to get it working using the convoluted procedure given in the replies to that issue.

I've worked around it this time, but I wanted you to know the propblem is still alive and well and impacting users.

Steps to reproduce

It happened EVERY time I created a new Project/Solution with the option "Windows Forms App [C#]". I tried a total of 6 different Projects, 4 w/ NET 8.0, 2 with NET 6.0, with different names and folder locations. I did not modify any of the auto-generated code or other files.

DISCOVERY: I tried it again while preparing this report, and this time I UNchecked the "Place solution and project in the same directory" option, and it worked right! Then I created one more project, with the box checked again, and it failed in the same manner. That option seems to matter for some reason.

Diagnostics

Here are the contents of the Output Window immediately after opening the Project/Solution for the first time:

[17:14:47.443540] fail: OutputGroupService didn't return output group DesignerRuntimeImplementationProjectOutputGroup.

                        For information on how to troubleshoot the designer refer to the guide at https://aka.ms/winforms/designer/troubleshooting.
[17:14:47.444616] fail: Could not retrieve DesignerRuntimeImplementationProjectOutputGroup for current project.

                        For information on how to troubleshoot the designer refer to the guide at https://aka.ms/winforms/designer/troubleshooting.
[17:14:47.451539] fail: System.InvalidOperationException: Designer load encountered an error. Please ensure that the project can be built successfully.
                           at Microsoft.DotNet.DesignTools.Client.Host.ProjectInfoProvider.NetCore.<GetNetCoreProjectInfoAsync>d__6.MoveNext()
                        --- End of stack trace from previous location where exception was thrown ---
                           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                           at Microsoft.DotNet.DesignTools.Client.Host.ProjectInfoProvider.<GetProjectInfoAsync>d__9.MoveNext()
                        --- End of stack trace from previous location where exception was thrown ---
                           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                           at Microsoft.DotNet.DesignTools.Client.Host.ServerHostFactory.<CreateHostAsync>d__8.MoveNext()
                        --- End of stack trace from previous location where exception was thrown ---
                           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                           at Microsoft.DotNet.DesignTools.Client.DesignToolsClientLoader.<CreateClientAsync>d__29.MoveNext()

                        For information on how to troubleshoot the designer refer to the guide at https://aka.ms/winforms/designer/troubleshooting.
[17:14:47.782137] warn: Cannot update selection in server process as Session is not connected.
elachlan commented 2 months ago

@Olina-Zhang can your team please test this?

Olina-Zhang commented 2 months ago

@Olina-Zhang can your team please test this?

We cannot reproduce this issue for creating WinForms .NET apps with Check/Uncheck the "Place solution and project in the same directory" option.

merriemcgaw commented 2 months ago

We'll talk to some partner teams and see what else we can find out. @Olina-Zhang can you move this to the designer repo?

CCarneySIA commented 2 months ago

Thank you for the continued effort to track this down. While this "bug" doesn't affect my work (b/c I have a work around), I have tested it again and the problem is very real on my work PC. I suspect for others as well. Clearly there is some dependency on how VS is installed.

If I can be helpful in any way to the debugging effort, let me know--I would be happy to participate.

Curtis Carney

John-Qiao commented 2 months ago

@merriemcgaw Filed a DT issue: 5925 for this issue.

sgf commented 1 month ago

Please open VS2022 with administrator privileges first, and then open the solution from the VS project list, and the problem will disappear.

Shyam-Gupta commented 1 month ago

@CCarneySIA Could you please check if @sgf's suggestion work for you? Ideally there should not be any need to elevate Visual Studio to run WinForms designer unless there is some permissions issue coming into play.

@sgf On your machine, do you always need to elevate VS to open the designer? For both new and existing projects? Without elevating VS, do you get this same error in output window - "Could not retrieve DesignerRuntimeImplementationProjectOutputGroup for current project." ?

sgf commented 1 month ago

@sgf On your machine, do you always need to elevate VS to open the designer? For both new and existing projects? Without elevating VS, do you get this same error in output window - "Could not retrieve DesignerRuntimeImplementationProjectOutputGroup for current project." ?

Currently I have two computers, one of which requires this(elevating VS) and the other does not.

I have encountered similar problems on 2 PCs in the past few years. But I don't know what causes it. I have searched a lot of information on the Internet, and this problem seems to have existed many years ago.

This is the error message I encountered. image

If do not upgrade VS, this problem can be stably reproduced and will definitely appear every time.

CCarneySIA commented 1 month ago

I opened VS in Admin mode, then created a new NET 8.0 WinForms Project (C#). As previously, it got stuck when it tried to open From1.cs in the designer. I closed VS, and then reopened it in Admin mode. I selected my new project from the recent list, as suggested by Soar. The project opened and the Form was displayed correctly in the designer. Their suggestion worked for me.

To see if the solution was sticky, I closed VS again, and re-opened in Normal access (not Admin). Opened my new project (this time using the File, Open menu item). I was able to open Form1.cs in the designer. Soar’s suggestion fixed the problem going forward. It is a better work-around than the previous approach (from this previous issue: https://github.com/dotnet/winforms/issues/8996#issuecomment-1518702857).

Thank you for your continued work to track down this bug… your diligence speaks well for your team.

Curt Carney.