在Visual Studio 2026的设计器中看不到用户控件
我们有一个Winforms项目:
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
</PropertyGroup>
我们注意到,在Visual Studio 2017及以上版本,放在表单上的任何 UserControl 在设计器中不可见,也在文档大纲窗口中不可见:
public partial class gttFilterControl : UserControl
{
public gttFilterControl()
{
InitializeComponent();
}
// ...
}
该 UserControl 位于同一个解决方案中,但在不同的项目中,使用相同的 TargetFramework。
如果我在VS2022中打开该项目,那么所有的 UserControl 都会出现在设计器中。是我们缺少某个设置吗,还是其他原因?
当我把我们的一些用户控件放到表单上时,我得到下面这个
Failed to create component 'gttFilterControl'. The error message follows:
'Microsoft.DotNet.DesignTools.Client.DesignToolsServerException: Method not found: 'System.Collections.Immutable.ImmutableArray`1
System.Reflection.Metadata.TypeName.GetGenericArguments()'. at Microsoft.DotNet.DesignTools.Client.DesignToolsClient.d__49
1.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.JoinableTask1.CompleteOnCurrentThread()
at Microsoft.DotNet.DesignTools.Protocol.Endpoints.DesignToolsEndpoints.DesignerHostsImpl.CreateComponent(SessionId sessionId, TypeIdentity type, String name, NameValuePairs defaultValues)
at Microsoft.WinForms.DesignTools.Client.Toolbox.WinFormsToolboxItem.CreateComponentsCore(IDesignerHost host, IDictionary defaultValues)
at System.Drawing.Design.ToolboxItem.CreateComponents(IDesignerHost host, IDictionary defaultValues)
at Microsoft.DotNet.DesignTools.Client.Designers.ComponentProxyDesigner.CreateTool(ToolboxItem tool, Nullable1 location, Nullable1 size, ObjectProxy toolboxSnapArgs)'
解决方案
In Visual Studio 18 there is a bug that causes the WinForms designer to fail when using System.Reflection.Metadata version 10.x.
The designer's out-of-process design-time host expects version 8.x APIs (matching .NET 8 runtime), but version 10.x includes additional APIs that cause method resolution failures.
This results in errors like Method not found: GetGenericArguments(), preventing custom UserControls from being instantiated at design-time and making the visual designer unusable for forms containing custom controls.
For that reason, we need to pin the versions of System.Reflection.Metadata and System.Resources.Extensions to prevent unintentional upgrades that would break the designer experience for our users.
We decided to pin the versions of System.Reflection.Metadata and System.Resources.Extensions to [8.0.0, 9.0.0) to allow any 8.x version but block 9.x and 10.x.
We also will monitor Microsoft's Visual Studio release notes for fixes to the WinForms Designer. Test with newer versions of VS 2025 updates. Once the designer works with version 10.x packages, these locks can be removed.