dotnet / winforms

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

An error occurred in the design interface after adding <PublishAot>true</PublishAot> #10986

Closed Nora-Zhou01 closed 8 months ago

Nora-Zhou01 commented 8 months ago

.NET version

.NET 9.0.100-preview.3.24128.12

Did it work in .NET Framework?

Not tested/verified

Did it work in any of the earlier releases of .NET Core or .NET 5+?

It doesn't repro on .NET 7.0, repro from .NET 8.0 to .NET 9.0.

Issue description

An error occurred in the design interface after adding true to the .csproj file

Call stack:

at Microsoft.DotNet.DesignTools.Client.Host.ProjectInfoProvider.NetCore.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.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.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.DesignToolsClientLoader.d__29.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.<>c__DisplayClass25_1.<<-ctor>b__1>d.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.d__27.MoveNext() 

https://github.com/dotnet/winforms/assets/104609169/62ac4311-c81a-482f-9e74-56218398cad6

Expected result:

https://github.com/dotnet/winforms/assets/104609169/e9635126-cd65-42ed-aa1a-09cc7fc3c817

Steps to reproduce

  1. Create Winforms .NET Core project
  2. Close the Form.cs[Design] interface
  3. Add the following code to the .csproj file: <PublishAot>true</PublishAot>
  4. Save all
  5. Double-click Form.cs in solution explorer to open the designer interface

More info:

  1. The initial feedback ticket is: https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1977108
  2. This problem also repro in VB projects
  3. The error is different in .NET8.0 project Exception Message:

    
    [07:57:35.497120] fail: [WinFormsApp75]: Failed to launch design tools server process process
                        System.InvalidOperationException: Reflection-based serialization has been disabled for this application. Either use the source generator APIs or explicitly configure the 'JsonSerializerOptions.TypeInfoResolver' property.
                           at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_JsonSerializerIsReflectionDisabled()
                           at System.Text.Json.JsonSerializerOptions.ConfigureForJsonSerializer()
                           at System.Text.Json.JsonSerializer.GetTypeInfo(JsonSerializerOptions options, Type inputType)
                           at System.Text.Json.JsonSerializer.GetTypeInfo[T](JsonSerializerOptions options)
                           at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
                           at Microsoft.WinForms.Utilities.Desktop.Manifest.ServerManifest.NetCore.TryLoadFromFileAsync(String sourceDirectory)
                           at Microsoft.DotNet.DesignTools.Server.DesignToolsServer.StartUpAsync(Boolean testMode, CancellationToken cancellationToken)
                           at Microsoft.DotNet.DesignTools.Server.DesignToolsServer.StartListeningAsync(Stream stream, TraceListener traceListener)
                           at Microsoft.DotNet.DesignTools.Server.Program.<>c__DisplayClass2_0.<<Main>b__1>d.MoveNext()
    
                        For information on how to troubleshoot the designer refer to the guide at https://aka.ms/winforms/designer/troubleshooting.
    [07:57:35.511120] fail: Microsoft.DotNet.DesignTools.Client.ServerException: Failed to launch the design tools server process.
                           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                           at Microsoft.VisualStudio.Threading.TplExtensions.<WithTimeout>d__5.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.ServerProcess.<LaunchAsync>d__28.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__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.DesignToolsClientLoader.<CreateClientAsync>d__29.MoveNext()
    
                        For information on how to troubleshoot the designer refer to the guide at https://aka.ms/winforms/designer/troubleshooting.
    [07:57:35.555122] fail: Microsoft.DotNet.DesignTools.Client.ServerException: Failed to launch the design tools server process.
                           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                           at Microsoft.VisualStudio.Threading.TplExtensions.<WithTimeout>d__5.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.ServerProcess.<LaunchAsync>d__28.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__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.DesignToolsClientLoader.<CreateClientAsync>d__29.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.<>c__DisplayClass25_1.<<-ctor>b__1>d.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.<GetClientAsync>d__27.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.WinForms.VSDesignSurface.<RecreateDesignerSessionAsync>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.VisualStudio.WinForms.ProjectWatchers.ProjectWatcherService.ProjectWatcher.<>c__DisplayClass65_1.<<RestartServerProcessAndReloadDesignerIfRequired>g__RecreateDesignerSessionAndReloadDesignerAsync|1>d.MoveNext()
                        --- End of stack trace from previous location where exception was thrown ---
                           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                           at Microsoft.VisualStudio.WinForms.ProjectWatchers.ProjectWatcherService.ProjectWatcher.<>c__DisplayClass65_1.<<RestartServerProcessAndReloadDesignerIfRequired>g__RecreateDesignerSessionAndReloadDesignerAsync|1>d.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.WinForms.ProjectWatchers.ProjectWatcherService.ProjectWatcher.<>c__DisplayClass65_0.<<RestartServerProcessAndReloadDesignerIfRequired>b__0>d.MoveNext()
    
                        For information on how to troubleshoot the designer refer to the guide at https://aka.ms/winforms/designer/troubleshooting.


https://github.com/dotnet/winforms/assets/104609169/ac0ba94e-55b1-4068-b586-7bd019d10b8a
merriemcgaw commented 8 months ago

@Nora-Zhou01 can you please copy this one to the designer - I think we're most likely dealing with this error when we launch the server process, rather than doing something in the runtime. You can close this one when you're done. It might be interesting to also test what happens in WPF apps when this is turned on.

Nora-Zhou01 commented 8 months ago

@merriemcgaw Filed issue 5827 to track it ,this issue cannot be reproduced in WPF project.