Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Could not find type" error loading a form in the Windows Forms Designer

I have a .NET 2.0 windows forms app, which makes heavy use of the ListView control.

I've subclassed the ListView class into a templated SortableListView<T> class, so it can be a bit smarter about how it displays things, and sort itself.

Unfortunately this seems to break the Visual Studio Forms Designer, in both VS2005 and 2008.

The program compiles and runs fine, but when I try view the owning form in the designer, I get these Errors:

  • Could not find type 'MyApp.Controls.SortableListView'. 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.

There is no stack trace or error line information available for this error

  • The variable 'listViewImages' is either undeclared or was never assigned.

At MyApp.Main.Designer.cs Line:XYZ Column:1

Call stack: at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)  

The line of code in question is where it is actually added to the form, and is

this.imagesTab.Controls.Add( this.listViewImages ); 

listViewImages is declared as

private MyApp.Controls.SortableListView<Image> listViewImages; 

and is instantiated in the InitializeComponent method as follows:

this.listViewImages = new MyApp.Controls.SortableListView<Image>(); 

As mentioned earlier, the program compiles and runs perfectly, and I've tried shifting the SortableListView class out to a seperate assembly so it can be compiled seperately, but this makes no difference.

I have no idea where to go from here. Any help would be appreciated!

like image 422
Orion Edwards Avatar asked Aug 12 '08 23:08

Orion Edwards


2 Answers

It happened to me because of x86 / x64 architecture.

Since Visual Studio (the development tool itself) has no x64 version, it's not possible to load x64 control into GUI designer.

The best approach for this might be tuning GUI under x86, and compile it for x64 when necessary.

like image 108
Val Avatar answered Sep 28 '22 09:09

Val


when you added the listview, did you add it to the toolbox and then add it to the form?

No, I just edited Main.Designer.cs and changed it from System.Windows.Forms.ListView to MyApp.Controls.SortableListView<Image>

Suspecting it might have been due to the generics led me to actually finding a solution.

For each class that I need to make a SortableListView for, I defined a 'stub class' like this

class ImagesListView : SortableListView<Image> { } 

Then made the Main.Designer.cs file refer to these stub classes instead of the SortableListView.

It now works, hooray!

Thankfully I am able to do this because all my types are known up front, and I'm only using the SortableListView as a method of reducing duplicate code.

like image 33
Orion Edwards Avatar answered Sep 28 '22 09:09

Orion Edwards