Could not find type 'xxx.xxx.xxx'. Please make sure that the assembly

假如想象 提交于 2019-12-17 17:47:12

问题


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)


回答1:


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




回答2:


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



回答3:


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:


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.




回答5:


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.




回答6:


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.




回答7:


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.




回答8:


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




回答9:


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.




回答10:


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.




回答11:


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



回答12:


You can change to any CPU:

Project => properties => Build

Platform target: Change to Any CPU

Clean and Rebuild, Reopen the Design file.



来源:https://stackoverflow.com/questions/19009386/could-not-find-type-xxx-xxx-xxx-please-make-sure-that-the-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!