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 build 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 64bit it doens't work and I get this designer error. However, if I switch it to 32bit (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)
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:
- Change the solution to 32bit
- Clean and rebuild the solution
- Open the GUI for editing
- Save, change the solution back to 64bit
- Clean and rebuild
- Run in 64bit
See this question for more details.
VS 2010 designer error 'Could not find type XYZ' in Windows7. Works fine in XP
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:
- Rename a type, which is missing (for example InformationBox => InformationBox2)
- Refresh designer (WOW, it works!)
- Rename the type to its initial name
Change Any CPU to X86. Your control is 32bit trying to run on 64bit machine and cannot find the 64bit version of the control.
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:
- Clean the entire solution
- Close Visual Studio
- Re-open Visual Studio
- Re-open the solution
- Build the solution by right-clicking it in Solution Explorer (Not Rebuild, that didn't work)
- 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.
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.
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.
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.
Just save your project, close it then reopen it again.
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.
You can change to any CPU
Project => properties => Build
Platform target: Change to Any CPU
Clean and Rebuild , Reopen the Design file
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!
- You can either change to AnyCPU
- build for x86 then the Visual Studio designer is able to load your assemblies to show your controls at design time
- Don't design with x64 assemblies, build them only via batch or in Visual Studio and then switch back to AnyCPU or x86
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.
来源:https://stackoverflow.com/questions/19009386/could-not-find-type-xxx-xxx-xxx-please-make-sure-that-the-assembly