51
votes

I've searched StackOverflow and found similar problems when I try and open a form that references a UserControl in a different project.

I get the

To prevent possible data loss before loading the designer, the following errors must be resolved:

message relating to the following two errors:

Could not find type 'MyNamespace.CommonUi.InformationBox'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built using settings for your current platform or Any CPU.

AND

The variable 'InformationBox1' is either undeclared or was never assigned.

InformationBox1 is an instance of the user control InformationBox that is on the form in the designer - it's just referenced as;

Friend WithEvents InformationBox1 As MyNamespace.CommonUi.InformationBox

The MyNamespace.CommonUi project builds successfully.

I get intellisense in the project so I'm reasonably confident that it's being referenced correctly.

So far, the same as other people have had:

This is a project that's been migrated from .NET2/x86 in VS2005 to .NET4/x64 in VS2012.

Now when the solution is running under 64 bit it doesn't work and I get this designer error. However, if I switch it to 32 bit (well technically AnyCPU) I can open the designer just fine.

I've read through the other suggestions in similar threads but they don't see to provide any solution (I've even gone as far as the "move it left & right to get it to rebuild" option)

14
Whenever I get something like this, I go through these steps, if you have not done this, maybe it will help: 1-Close all forms in the IDE, 2-Clean the solution, 3-Rebuild the solution.Steve
Nope, tried that. Several times. There's nothing wrong with the .designer.vb code as far as I can tell and the rebuilding doesn't change any of it (tried a compare before & after)Andy Macnaughton-Jones
Clearing and Rebuilding my project worked for me!M. Fawad Surosh

14 Answers

72
votes

I believe the issue is that Visual Studio is natively 32bit and one cannot do GUI editing for some components (E.g. ListView) in 64bit. E.g. on forms where you have ListView, you need to change the solution to 32bit to edit the GUI.

So the answer in short is, when you're facing this issue:

  1. Change the solution to 32bit or AnyCPU
  2. Clean and rebuild the solution/project
  3. Open the GUI for editing
  4. Save, change the solution back to 64bit
  5. Clean and rebuild
  6. Run in 64bit

Unfortunately Visual Studio doesn't come in 64bit as yet, hence all controls need to be designed in 32bit mode (or AnyCPU mode).

See this question for more details.

VS 2010 designer error 'Could not find type XYZ' in Windows7. Works fine in XP

16
votes

I had this problem. It happened only in one form designer view, despite it was able to compile, start, show this form in runtime and show other forms / controls in designer mode.

These steps didn't help:

  • Clean & rebuild
  • Restart studio
  • Deleting all bin and obj directories
  • Removing and adding references
  • Denial, anger, bargaining, depression, acceptance

Solution for my case:

  1. Rename a type, which is missing (for example InformationBox => InformationBox2)
  2. Refresh designer (WOW, it works!)
  3. Rename the type to its initial name
10
votes

Change Any CPU to X86. Your control is 32bit trying to run on 64bit machine and cannot find the 64bit version of the control.

4
votes

I had this same error recently with VB.Net in Visual Studio 2013 working with a custom WinForm User Control that itself was inheriting a custom user control base class in the same project, and took some doing to find out what the true cause was, which in my case was that neither base class nor the child class had a no-parameter constructor (Because that's not a valid scenario in this case).
To fix it, I added the missing constructor but left it empty (throwing a NotImplementedException caused another issue that prevented it from displaying). It's not pretty, but it works.

In order to see the underlying error through the one listed in this threads question, I had to do the following:

  1. Clean the entire solution
  2. Close Visual Studio
  3. Re-open Visual Studio
  4. Re-open the solution
  5. Build the solution by right-clicking it in Solution Explorer (Not Rebuild, that didn't work)
  6. View the User Control in Designer mode and the actual error shows up now

After adding the constructor, I had to take the above steps again to make it work properly.

3
votes

I changed a large solution with multiple projects to target x64 platform from AnyCPU. Tried opening the designer of one of the solution forms which referenced a control in one of the other projects and got the same error message as the OP. Opened the project that contained the control and saw it still targeted AnyCPU. Tried for an hour to get it to save as x64 with no luck. I eventually opened the csproj file in notepad, replaced AnyCPU with x64 and it all started working. Hopefully this helps someone else as frustrated as I was.

3
votes

Recently I encountered the same problem with one of my custom controls (C#) in VS 2015.

I solved it by cleaning the solution (Build -> Clean Solution) and then rebuild the whole solution. Everything came back smoothly.

My project settings' platform target is already set to "Any CPU" and checkbox ticked for "Prefer 32-bit". Not sure why it happened though.

2
votes

While there is a lot of reference to 32-bit etc, the steps that worked for me were :

  • Convert all references to the user control, say, 'InformationBox1 as InformationBox' into a fully qualified class reference such as 'MyNamespace.CommonUi.InformationBox', in all the designer.vb files.

    • Clean Solution

    • Rebuild Solution.

In my case, it was a migration project from VB6 to VS2008 and both the environments were 32-bit, and on the same machine, there was no sign of 64-bit involved.

2
votes

Well here's some further information: the-designer-could-not-be-shown-with-platform-x64

And the resolution to run in AnyCPU, when you are trying to access the designer is a work-around and for our purposes will suffice.

2
votes

Just save your project, close it then reopen it again.

1
votes

What i think that you should keep you controls UI in separate project from your 64 bit project and run it with settings any CPU. this will help to not clean and rebuild it with 64 version.

1
votes

This happens if you compiling for x64 because the Visual Studio designer cannot load x64 assemblies. The designer of Visual Studio can only load x86 assemblies because it's an 32 bit only process!

  1. You can either change to AnyCPU
  2. build for x86 then the Visual Studio designer is able to load your assemblies to show your controls at design time
  3. Don't design with x64 assemblies, build them only via batch or in Visual Studio and then switch back to AnyCPU or x86
1
votes

You can change to any CPU:

Project => properties => Build

Platform target: Change to Any CPU

Clean and Rebuild, Reopen the Design file.

1
votes

I have the same problem and I solved it by:

  1. Going to properties of your solution in visual studio.
  2. Chaging 'Platform' to 'AnyCPU'.
  3. Rebuilding your solution.
  4. Restarting visual studio.
0
votes

I know this is a really old question/issue. However, I thought some should know that the latest VS 2022 (Preview) is now native 64-bit and can handle custom objects in a x64 designer mode when building a 64-bit application.