Search code examples
c#.netvisual-studiowinformscustom-controls

How to add a 32-bit Custom Windows Forms Control into Visual Studio Toolbox in vs2022(64-bit)


I want to add a 32-bit Custom Windows Forms Control into Visual Studio Toolbox in vs2022(64-bit). What I have tried: "Toolbox"->"choose items"->then import the "xxx.dll" as ".Net Framework components".However, it shows that the file "xxx.dll" is not valid.

Shyam Gupta(Senior Software Engineer, Windows Forms) says that the vs2022(64-bit) can't load the 32-bit resemblies/components, in the .net blog

some useful documents: document-1,document-2,document-3


Solution

  • Visual Studio 2022 is a 64-bit process and it cannot load 32-bit assemblies. Due to this technical limitation, Windows Forms .NET Framework in-process designer, which runs in the Visual Studio process, cannot load controls present in 32-bit assemblies. This has been a major Visual Studio 2022 adoption blocker for customers who have Windows Forms .NET Framework projects which utilize ActiveX/COM controls or other custom controls contained in 32-bit assemblies and which cannot be updated to AnyCPU or to .NET. Until now, such projects could only use Windows Forms designer in Visual Studio 2019 because it is a 32-bit process.

    Previous versions of Visual Studio targeted 32-bit, and your project probably compiled to AnyCPU, which would pick 32-bit while in design mode to match Visual Studio. 32-bit specific references worked, but if you had a 64-bit specific reference, you might have run into a problem with the designer. With Visual Studio 2022, the problem reversed. Visual Studio 2022 is only available in 64-bit. Components and libraries that were compiled as AnyCPU work in both 32-bit and 64-bit and don't have an issue running in Visual Studio 2022 64-bit. But, after upgrading to Visual Studio 2022, your projects might fail to run at design-time if the project relies on a 32-bit specific component. This is even the case when your referenced component is compiled for AnyCPU, but happens to reference a 32-bit component or 32-bit COM\ActiveX library directly.