dotnet / winforms

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

Unable to use out-of-process designer on .NET 6 Windows Forms projects with Wpf references #10804

Open bh-sijtnic opened 9 months ago

bh-sijtnic commented 9 months ago

Environment

Using Windows 10 Version 22H2 (19045.3930) Microsoft Visual Studio Enterprise 2022 (64-bit) - LTSC 17.6 - Version 17.6.11 Repaired my Visual Studio 2022 installation, no change

.NET version

.NET6-Windows10.0.19041

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

.NET Framework 4.7.2

Issue description

We have recently upgrade all out projects .NET 6. Many of our software developers experience that they are unable to use the WinForms designer in VS on the .NET 6 projects. For some users it does work. We followed the troubleshooting guide, but no luck.

We found the out-of-process documentation and enabled both the out of process designers image

I have managed to reproduce my problems in a sample project, so i will report this behaviour. I set the Windows Forms log verbosity to detailed.

When creating a new solution in VS 2022, creating a Windows Forms net6.0-windows project with the default form, the designer can load, showing the default empty form. This produces below output (in diagnostics section) and properly shows the DesignToolsServer.exe as a child process of the Visual Studio instance. image

To break this, all i need to do is add a PackageReference to one of the DevExpress WPF packages, which in our production code might happen using transitive dependencies.

  <ItemGroup>
    <PackageReference Include="DevExpress.Wpf.Core" Version="22.2.4" />
  </ItemGroup>

After doing this, without even using any controls, the DesignToolServer is failing to load, producing this below log file.

If have also tested using the DevExpress.Win.Design package, when adding a reference to this the design still loads.

Sometimes, but not always, i am seeing this exception when closing the hanging designer image

[09:29:59.715898] fail: Exception occurred while disposing VSDesignSurface
                        System.InvalidOperationException: The service 'Microsoft.VisualStudio.Shell.Design.Serialization.DesignerDocDataService' must be installed for this feature to work.  Ensure that this service is available.
                           at System.ServiceExtensions.GetRequiredService[TService,TInterface](IServiceProvider provider)
                           at Microsoft.DotNet.DesignTools.Client.CodeDom.VsDesignerInfo.<CreateAsync>d__22.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.CodeDom.CodeDomSource.<CreateAsync>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.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread()
                           at Microsoft.VisualStudio.Threading.JoinableTask`1.CompleteOnCurrentThread()
                           at Microsoft.DotNet.DesignTools.Client.Loader.VsDesignerLoader.<get_CodeDomSource>g__Create|36_0()
                           at Microsoft.DotNet.DesignTools.Client.Loader.VsDesignerLoader.get_CodeDomSource()
                           at Microsoft.DotNet.DesignTools.Client.Loader.VsDesignerLoader.get_CodeDomManager()
                           at Microsoft.DotNet.DesignTools.Client.Loader.VsDesignerLoader.OnBeginUnload()
                           at Microsoft.DotNet.DesignTools.Client.Loader.BasicDesignerLoader.Dispose()
                           at Microsoft.DotNet.DesignTools.Client.Loader.VsDesignerLoader.Dispose()
                           at System.ComponentModel.Design.DesignerHost.DisposeHost()
                           at System.ComponentModel.Design.DesignSurface.Dispose(Boolean disposing)
                           at Microsoft.VisualStudio.WinForms.VSDesignSurface.Dispose(Boolean disposing)

                        For information on how to troubleshoot the designer refer to the guide at https://aka.ms/winforms/designer/troubleshooting.

Steps to reproduce

Create new solution with NET 6 Windows Forms project Add PackageReference to DevExpress.Wpf.Core version 22.2.4 Open designer

Diagnostics

Failed designer log:
[09:52:45.428236] info: Creating VsDesignerLoader
[09:52:45.478237] info: [Thread 1] Creating design-time ITypeResolutionService.
[09:52:45.535236] trce: Current VS Version = 17.0
[09:52:45.536236] trce: Package path = C:\Users\user\.nuget\packages\devexpress.wpf.core\22.2.4
[09:52:45.536236] trce: Root directory selected for design assemblies = C:\Users\user\.nuget\packages\devexpress.wpf.core\22.2.4\lib\net6.0-windows\design
[09:52:45.546238] info: Start processing enqueued assemblies
[09:52:45.546238] trce: Loaded Microsoft.WinForms.DesignTools.Protocol in 00:00:00.0000087 [thread 11]
[09:52:45.547238] trce: Processed 'Microsoft.WinForms.DesignTools.Protocol' in 00:00:00.0006245
[09:52:45.549238] info: Added 'Microsoft.WinForms.DesignTools.Protocol'
[09:52:45.549238] trce: Loaded Microsoft.WinForms.DesignTools.Client in 00:00:00.0000052 [thread 11]
[09:52:45.564238] trce: Processed 'Microsoft.WinForms.DesignTools.Client' in 00:00:00.0150557
[09:52:45.565238] info: Added 'Microsoft.WinForms.DesignTools.Client'
[09:52:45.565238] trce: Loaded DesignerRunner in 00:00:00.0000250 [thread 11]
[09:52:45.578238] trce: Processed 'DesignerRunner' in 00:00:00.0126511
[09:52:45.578238] info: Added 'DesignerRunner'
[09:52:45.578238] trce: Loaded DevExpress.Xpf.Core.v22.2.DesignTools in 00:00:00.0000066 [thread 11]
[09:52:45.593238] trce: Processed 'DevExpress.Xpf.Core.v22.2.DesignTools' in 00:00:00.0153176
[09:52:45.594237] info: Added 'DevExpress.Xpf.Core.v22.2.DesignTools'
[09:52:45.594237] trce: Loaded DevExpress.Xpf.Core.v22.2.DesignTools.v16.10 in 00:00:00.0000059 [thread 11]
[09:52:45.597238] trce: Processed 'DevExpress.Xpf.Core.v22.2.DesignTools.v16.10' in 00:00:00.0026215
[09:52:45.598238] info: Added 'DevExpress.Xpf.Core.v22.2.DesignTools.v16.10'
[09:52:45.779235] trce: Processed 'System.Windows.Forms' in 00:00:00.0023830
[09:52:45.790235] info: Added 'System.Windows.Forms'
[09:52:45.790235] trce: Loaded System in 00:00:00.0000125 [thread 13]
[09:52:45.790235] trce: Processed 'System' in 00:00:00.0004613
[09:52:45.847235] info: Added 'System'
[09:52:45.847235] trce: Loaded System.Drawing in 00:00:00.0000113 [thread 13]
[09:52:45.847235] trce: Processed 'System.Drawing' in 00:00:00.0001099
[09:52:45.848234] info: Added 'System.Drawing'
[09:52:45.848234] trce: Loaded System.Design in 00:00:00.0000052 [thread 13]
[09:52:45.903459] trce: Processed 'System.Design' in 00:00:00.0552288
[09:52:45.910458] info: Added 'System.Design'
[09:52:45.910458] trce: Loaded System.Drawing.Design in 00:00:00.0000121 [thread 13]
[09:52:45.912457] trce: Processed 'System.Drawing.Design' in 00:00:00.0013435
[09:52:45.912457] info: Added 'System.Drawing.Design'
[09:52:46.523648] warn: Cannot update selection in server process as Session is not connected.
[09:56:13.004058] trce: Suspend painting the design surface
[09:56:13.014052] warn: Cannot update selection in server process as Session is not connected.

Working designer log:
[09:36:07.465358] info: Creating VsDesignerLoader
[09:36:07.520361] info: [Thread 1] Creating design-time ITypeResolutionService.
[09:36:07.561361] info: Start processing enqueued assemblies
[09:36:07.561361] trce: Loaded Microsoft.WinForms.DesignTools.Protocol in 00:00:00.0000105 [thread 53]
[09:36:07.562361] trce: Processed 'Microsoft.WinForms.DesignTools.Protocol' in 00:00:00.0006434
[09:36:07.564371] info: Added 'Microsoft.WinForms.DesignTools.Protocol'
[09:36:07.564371] trce: Loaded Microsoft.WinForms.DesignTools.Client in 00:00:00.0000047 [thread 53]
[09:36:07.579362] trce: Processed 'Microsoft.WinForms.DesignTools.Client' in 00:00:00.0155389
[09:36:07.580365] info: Added 'Microsoft.WinForms.DesignTools.Client'
[09:36:07.679370] info: Visual Studio culture: en-US (0x0409)
[09:36:07.680369] info: [Thread 15] Launching server...
[09:36:07.684368] info: Is processor architecture ARM64: False
[09:36:07.822374] info: Added 'System.Windows.Forms'
[09:36:07.822374] trce: Loaded System in 00:00:00.0000106 [thread 17]
[09:36:07.823374] trce: Processed 'System' in 00:00:00.0006417
[09:36:07.835382] info: Added 'System'
[09:36:07.835382] trce: Loaded System.Drawing in 00:00:00.0000132 [thread 16]
[09:36:07.835382] trce: Processed 'System.Drawing' in 00:00:00.0000980
[09:36:07.837381] info: Added 'System.Drawing'
[09:36:07.837381] trce: Loaded System.Design in 00:00:00.0000070 [thread 16]
[09:36:07.902378] trce: Processed 'System.Design' in 00:00:00.0653759
[09:36:07.935376] info: Added 'System.Design'
[09:36:07.935376] trce: Loaded System.Drawing.Design in 00:00:00.0000129 [thread 16]
[09:36:07.937376] trce: Processed 'System.Drawing.Design' in 00:00:00.0015655
[09:36:07.937376] info: Added 'System.Drawing.Design'
[09:36:08.524180] info: Shadow cache base directory: C:\Users\user\AppData\Local\Microsoft\VisualStudio\17.0_8df71e82\WinFormsDesigner
[09:36:08.529181] info: [WinFormsApp1]: Preparing shadow cache folder.
[09:36:08.530241] info: [WinFormsApp1]: NetCoreServerLayout - Platform: x64, Normalized PlatformName: x64
[09:36:08.532180] info: [WinFormsApp1]: Copying design tools server common files from: 'c:\program files\microsoft visual studio\2022\enterprise\common7\ide\commonextensions\microsoft\windows.forms\DesignToolsServer\Common'.
[09:36:08.571776] info: [WinFormsApp1]: Copying design tool server platform-specific files from: 'c:\program files\microsoft visual studio\2022\enterprise\common7\ide\commonextensions\microsoft\windows.forms\DesignToolsServer\x64'.
[09:36:08.580783] info: [WinFormsApp1]: Copying 'C:\Users\user\source\repos\WinFormsApp1\WinFormsApp1\obj\x64\Debug\net6.0-windows\WinFormsApp1.designer.deps.json' to 'DesignToolsServer.deps.json'
[09:36:08.582777] info: [WinFormsApp1]: Copying 'C:\Users\user\source\repos\WinFormsApp1\WinFormsApp1\obj\x64\Debug\net6.0-windows\WinFormsApp1.designer.runtimeconfig.json' to 'DesignToolsServer.runtimeconfig.json'
[09:36:08.712454] info: Shadow caching completed.
[09:36:08.716462] info: IServerConnectionTimeoutProvider: Starting execution of winFormsOptions task.
[09:36:08.717461] info: IServerConnectionTimeoutProvider: WinFormsOptions task completed.
[09:36:08.717461] info: Obtained ServerConnectionTimeout value: 120000.
[09:36:08.717461] info: Obtained OutputWindowLoggingService.
[09:36:08.722461] info: [WinFormsApp1]: Launching design tools server process...
[09:36:09.777331] info: [WinFormsApp1]: Connected to named pipe: DesignToolsServer.35bab616-28df-4ab3-afb3-02b4a65103a7
[09:36:09.798332] info: [WinFormsApp1]: Connecting to pipe: DesignToolsServer.35bab616-28df-4ab3-afb3-02b4a65103a7... 
[09:36:09.798332] info: [WinFormsApp1]: Successfully connected to pipe: DesignToolsServer.35bab616-28df-4ab3-afb3-02b4a65103a7
[09:36:09.804332] info: [WinFormsApp1]: Creating DesignToolsServer [thread 1]
[09:36:09.806331] info: [WinFormsApp1]: Starting UI thread [thread 1]
[09:36:09.814331] info: [WinFormsApp1]: Performing start up tasks [thread 6]
[09:36:09.941332] info: [WinFormsApp1]: UI thread started
[09:36:10.146331] info: [WinFormsApp1]: Wait for start up tasks to complete... [thread 6]
[09:36:10.182331] info: [WinFormsApp1]: Loaded server manifest [thread 10]
[09:36:10.183331] info: [WinFormsApp1]: Loading design-time assemblies [thread 10]
[09:36:10.314331] info: [WinFormsApp1]: Building MEF composition
[09:36:10.530436] info: [WinFormsApp1]: Start up tasks completed [thread 10]
[09:36:10.530436] info: [WinFormsApp1]: Initialize JsonRpc [thread 10]
[09:36:10.639436] info: [WinFormsApp1]: Start processing enqueued assemblies
[09:36:10.639436] info: [WinFormsApp1]: Listening for JSON RPC messages
[09:36:10.639436] info: [WinFormsApp1]: Design tools server process is running
[09:36:10.639436] info: [WinFormsApp1]: Design tools server process launch completed successfully.
[09:36:10.639436] trce: [WinFormsApp1]: Launching and connecting to the design tools server process took 00:00:01.9187185
[09:36:10.640435] info: [Thread 28] DesignToolsServer launch time = 2961 ms.
[09:36:10.640435] info: [Thread 28] Initializing client...
[09:36:10.649436] info: [Thread 28] DesignToolsClient init time = 8 ms.
[09:36:10.649436] info: [Thread 28] Initializing server...
...
[09:36:11.411161] trce: [WinFormsApp1]: Processed 'System.Text.RegularExpressions' in 00:00:00.0005129
[09:36:11.411161] info: [WinFormsApp1]: Added 'System.Text.RegularExpressions'
[09:36:11.413155] trce: [WinFormsApp1]: Loaded System.Threading.Channels in 00:00:00.0012772 [thread 11]
[09:36:11.413155] trce: [WinFormsApp1]: Processed 'System.Threading.Channels' in 00:00:00.0006795
[09:36:11.414166] info: [WinFormsApp1]: Added 'System.Threading.Channels'
[09:36:11.414166] trce: [WinFormsApp1]: Loaded System.Threading in 00:00:00.0000761 [thread 11]
[09:36:11.414166] trce: [WinFormsApp1]: Processed 'System.Threading' in 00:00:00.0001594
[09:36:11.414166] info: [WinFormsApp1]: Added 'System.Threading'
[09:36:11.415154] trce: [WinFormsApp1]: Loaded System.Threading.Tasks.Dataflow in 00:00:00.0011193 [thread 11]
[09:36:11.417161] trce: [WinFormsApp1]: Processed 'System.Threading.Tasks.Dataflow' in 00:00:00.0020575
[09:36:11.418162] info: [WinFormsApp1]: Added 'System.Threading.Tasks.Dataflow'
[09:36:11.419154] trce: [WinFormsApp1]: Loaded System.Threading.Tasks.Parallel in 00:00:00.0002490 [thread 11]
[09:36:11.419154] trce: [WinFormsApp1]: Processed 'System.Threading.Tasks.Parallel' in 00:00:00.0002162
[09:36:11.419154] info: [WinFormsApp1]: Added 'System.Threading.Tasks.Parallel'
[09:36:11.419154] trce: [WinFormsApp1]: Loaded System.Transactions.Local in 00:00:00.0002475 [thread 11]
[09:36:11.420161] trce: [WinFormsApp1]: Processed 'System.Transactions.Local' in 00:00:00.0010218
[09:36:11.421161] info: [WinFormsApp1]: Added 'System.Transactions.Local'
[09:36:11.421161] trce: [WinFormsApp1]: Loaded System.Web.HttpUtility in 00:00:00.0002027 [thread 11]
[09:36:11.422161] trce: [WinFormsApp1]: Processed 'System.Web.HttpUtility' in 00:00:00.0000717
[09:36:11.422161] info: [WinFormsApp1]: Added 'System.Web.HttpUtility'
[09:36:11.422161] trce: [WinFormsApp1]: Loaded System.Xml.XPath.XDocument in 00:00:00.0001969 [thread 11]
[09:36:11.422161] trce: [WinFormsApp1]: Processed 'System.Xml.XPath.XDocument' in 00:00:00.0000275
[09:36:11.422161] info: [WinFormsApp1]: Added 'System.Xml.XPath.XDocument'
[09:36:11.474164] trce: Sending request: DesignerHosts/GetDesigner
[09:36:11.477160] trce: DesignerHosts/GetDesigner took 00:00:00.0032763.
[09:36:11.514155] trce: Sending request: Actions/GetDesignerActionUI
[09:36:11.516155] trce: Actions/GetDesignerActionUI took 00:00:00.0024047.
[09:36:11.525226] trce: Notifying 1 'Components/ComponentAdded' handlers
[09:36:11.528214] trce: SessionId = 7368:1: Count of components present during Form load: 1
[09:36:11.528214] trce: SessionId = 7368:1: Document details: Namespace = "WinFormsApp1", Type = "Form1"
[09:36:11.580154] trce: Sending request: Sessions/EndLoad
[09:36:11.584159] trce: [WinFormsApp1]: Attempting to update selection: 1 components, Replace
[09:36:11.592153] trce: [WinFormsApp1]: Made change: True
[09:36:11.601159] trce: Sessions/EndLoad took 00:00:00.0203934.
[09:36:11.601159] trce: Notifying 1 'Selection/Changed' handlers
[09:36:11.607159] trce: Sending request: Objects/GetAttributes [1]
[09:36:11.610159] trce: Objects/GetAttributes took 00:00:00.0030295.
[09:36:11.620159] trce: Sending request: Objects/GetProperties
[09:36:11.688193] trce: Objects/GetProperties took 00:00:00.0683930.
[09:36:11.691191] trce: Sending request: Controls/GetChildren
[09:36:11.692979] trce: Controls/GetChildren took 00:00:00.0018529.
[09:36:11.717637] info: InputShield handle created.
[09:36:11.719636] trce: Sending request: Sessions/OnDesignerWindowParented
[09:36:11.721649] trce: Sessions/OnDesignerWindowParented took 00:00:00.0017004.
[09:36:11.723636] trce: Sending request: Sessions/UpdateDesignerWindowParentSize
[09:36:11.733637] trce: Sessions/UpdateDesignerWindowParentSize took 00:00:00.0095266.
[09:36:11.736637] trce: Sending request: Sessions/GetLanguageInfo
[09:36:11.740636] trce: Sessions/GetLanguageInfo took 00:00:00.0041243.
[09:36:11.741637] trce: Sending request: Sessions/DesignerActivated
[09:36:11.743637] trce: Sessions/DesignerActivated took 00:00:00.0018804.
[09:36:11.770507] trce: Sending request: Designers/GetDesignerVerbs
[09:36:11.783528] trce: Designers/GetDesignerVerbs took 00:00:00.0136103.
[09:36:11.785535] trce: Sending request: Designers/GetDesignerActionLists
[09:36:11.790352] trce: Designers/GetDesignerActionLists took 00:00:00.0052156.
merriemcgaw commented 9 months ago

@Olina-Zhang can your team take a look and reproduce the issue. Let us know if it is a regression and from when. If you narrow it down, go ahead and copy this over to the internal repo. Thanks!

Shyam-Gupta commented 9 months ago

@Olina-Zhang From the diagnostics information, it appears that server process crashed in this scenario. Once the issue reproes, please check if there is any error logged in system EventVwr. Thanks.

Olina-Zhang commented 9 months ago

Hi @Nico-1987 , @merriemcgaw, @Shyam-Gupta I am trying to reproduce it, but I cannot get the old DevExpress 22.2.4 version, it's 23.2.4 version now. So use the newer DevExpress 23.2.4 in Visual Studio 17.6.11 and 17.8.6, they work well: WinForms designer can be loaded successfully. @Nico-1987 Can you help confirm if I did the same steps as you(see following video), if yes, please use the latest DevExpress from https://www.devexpress.com/ to try again?

https://github.com/dotnet/winforms/assets/26474449/d385ce7e-6b74-4b7c-9e3c-36f6aa53c4b1

bh-sijtnic commented 9 months ago

HI @Olina-Zhang

I tried with version 23.2.4 as well, here the DesignToolsServer is loaded instantly and very rapid

image

We have multiple users in our group that cannot load the designer with 22.2.4 referenced, but some can. We dont understand the difference between the users, we all have the same Visual Studio versions.

bh-sijtnic commented 9 months ago

I drilled down a bit further into the package dependencies and found something interesting that fixes my test solution.

Inside the DevExpress.Wpf.Core 22.2.4 package they have a "DesignerRunner.exe" image

in the 22.2.4 package this lives in \design\designerrunner.exe

In the 23.2.4 package they have moved this into a subfolder \Server. image

In the 22.2.4 package, when i move the 3 files into a Server folder, the designer works again In the 23.2.4 package, when i move the files OUT of the server, mimicing the 22 structure, the designer stops working.

It looks like the existence of these files in this location makes the Visual Studio designer crash. Can you try to reproduce by changing the 23.2.4 packages structure on your machine?

Even with the 22.2.4 package change on my machine my production solution does not work yet, i will continue to look into that.

Edit: After making 2 more package changes, the designer started to work in production, while using 22.2.4 packages. For testing i moved some DevExpress design files into a subfolder

image And the other wpf.core

image

Without these files, the designer loads again. I found these locations from the DesignToolsServer output

[09:57:06.564116] trce: Package path = C:\Users\user\.nuget\packages\devexpress.wpf.core\22.2.4
[09:57:06.564116] trce: Root directory selected for design assemblies = C:\Users\user\.nuget\packages\devexpress.wpf.core\22.2.4\lib\net6.0-windows\design
[09:57:06.571106] trce: Package path = C:\Users\user\.nuget\packages\devexpress.wpf.grid.core\22.2.4
[09:57:06.571106] trce: Root directory selected for design assemblies = C:\Users\user\.nuget\packages\devexpress.wpf.grid.core\22.2.4\lib\net6.0-windows\design
[09:57:06.577106] trce: Package path = C:\Users\user\.nuget\packages\devexpress.wpf.docking\22.2.4
[09:57:06.577106] trce: Root directory selected for design assemblies = C:\Users\user\.nuget\packages\devexpress.wpf.docking\22.2.4\lib\net6.0-windows\design
[09:57:06.584114] info: Start processing enqueued assemblies

Question now is, what makes the DesignToolsServer crash on these files

Olina-Zhang commented 9 months ago

Can you try to reproduce by changing the 23.2.4 packages structure on your machine?

I tried to change the structure on my machine, it doesn't effect the designer loading. image

I am not sure how these packages files affect designer loading(DesignToolsServer), hopeful @Shyam-Gupta give your some answer.

bh-sijtnic commented 9 months ago

Broken: image

Working: image

merriemcgaw commented 9 months ago

@Shyam-Gupta will take a look at the causes here and reply.

bh-sijtnic commented 9 months ago

Small update from my end. I managed to upgrade out application to the latest DevExpress, version 23.2.4 While i had good results in my sample project, it is not working in our production projects (that reference more packages)

I did some further digging and i can reproduce the problem in my sample project by using this single reference

  <ItemGroup>
    <PackageReference Include="DevExpress.Wpf.Grid.Core" Version="23.2.4" />
  </ItemGroup>

image

Looking at the package, it seems this package still has the Interop files in the Design folder image

If i (re)move the VS2019 files, the designer starts to work! image

image