19
votes

I'm stuck on a problem in VS 2010 C# .NET. I've had a project on Windows XP that includes forms, classes and a handful of my own custom components. These components are simple extensions of built-in MS components (e.g. DataGridViewEx as an extension of DataGridView). Everything has worked fine in XP. I'm trying to port this project over to VS 2010 on Windows 7 / x64. I've got the solution to compile OK on Windows 7, however in design mode, when I open a form that contains one of the custom controls, I get an error 'Could not find type XYZ.DataGridViewEx. Please make sure that the assembly that contains this type is referenced.' XYZ is the namespace I use for these controls and it is the same namespace as the forms that are using the controls. All are part of the same VS project.

When I open a form in the same project that does not contain one of these custom controls, that form opens OK in the designer, and I see the custom controls along the left side in the toolbox. However if I then try to drag one of these controls into that form, it pops up an error message box 'Failed to load toolbox item 'DataGridViewEx'. It will be removed from the toolbox.' And then it gets removed from the toolbox.

Everything was always working fine in VS solution in XP. This problem only occurs in the VS solution in Windows 7 / x64.

I don't understand why it complains about not being able to find the component, since the component is part of the same project. That's a valid thing to do, isn't it?

I've search the web/forums and found cases of the 'Could not find type' error, but it seemed to be caused by a different issue, and I haven't yet found a way to get rid of the error.

Any help/tips are much appreciated!

10
I got it working by creating a new Class Library within the solution, and moving all the components from the original project over to the new class library, and changing the designer references to point to the new class library namespace. It was a pain, but it works.jble
i found that creating a new class essentially duplicated the problem into the newly named class...fa1c0n3r
@jble you should post your solution as an answer and mark it answered in case others stumble upon this.StoriKnow

10 Answers

23
votes

If your project is targeted at 64 bit, you need to build for 32 bit and choose the 32-bit solution while doing your GUI editing. This is because studio is 32-bit so cannot load 64-bit controls.

1
votes

Ive run into this before, be sure that in your Form.Designer.cs code file, that each call to your custom controls are done so as absolute calls. For example:

Namespace.CustomControl control;

Rather than

CustomControl control;
1
votes

Look at your references and find any that have exclamation point icons. Remove the bad references and add them back to your project.

0
votes

Have you tried disabling UAC completely (running IDE as Administrator + disabling UAC just in case). Also - always use Fusion Log for tracing assembly loads! See http://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.71).aspx for how to set it up

0
votes

Did you rebuild your components from scratch?

Are the projects included?

Are they all building?

Are they all building on the same platform (x86 vs x64)?

0
votes

Set the default built to x86 and that should fix it.

0
votes
  1. Clean the solution
  2. Build the project containing the Control
  3. Add the control to the toolbox/form

See if this works.

0
votes

For anyone who with similar issue(s). I just came across this in VS 2013 (VB side) on an x86 PC. As mentioned above, I toggled from 'anyCPU' to 'x86' and the form designer opened right up. Simple, but probably wouldn't have tried it without the above post(s). For what it's worth, I toggled back to 'anyCPU', and as yet have had no recurrences...

0
votes

I faced the same error, can't able to Build my application.

So searched here, Says to change the solution platform X64 or X32. But in my case the Solution platform only shows Any CPU and configuration manager option only

But i simply change the solution configuration.

Debug => Release

then

Release => Debug

Finally clean and rebuilt the solution. Its works for me!!:)

0
votes

While the top answer from @richard-whitehead is correct that the 64bit editor cannot load the 32bit controls which is why you're seeing the error, there is another way to have Visual Studio edit 32bit GUI controls in a 64bit GUI project as described here:

https://stackoverflow.com/a/26539992/2280961