<p>I have a .NET 2.0 windows forms app, which makes heavy use of the <code>ListView</code> control.</p>

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

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

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

<ul>
<li>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.</li>
</ul>

<p>There is no stack trace or error line information available for this error  </p>

<ul>
<li>The variable 'listViewImages' is either undeclared or was never assigned. </li>
</ul>

<p>At MyApp.Main.Designer.cs Line:XYZ Column:1</p>

<pre><code>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) 
</code></pre>

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

<pre><code>this.imagesTab.Controls.Add( this.listViewImages );
</code></pre>

<p>listViewImages is declared as</p>

<pre><code>private MyApp.Controls.SortableListView&lt;Image&gt; listViewImages;
</code></pre>

<p>and is instantiated in the <code>InitializeComponent</code> method as follows:</p>

<pre><code>this.listViewImages = new MyApp.Controls.SortableListView&lt;Image&gt;();
</code></pre>

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

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

[{'answer_id': 9320, 'author': 'lomaxx', 'author_id': 493, 'author_profile': 'https://Stackoverflow.com/users/493', 'pm_score': 3, 'selected': False, 'text': "<p>I've had a problem like this (tho not the same) in the past where my control was in a different namespace to my form even tho it was in the same project. To fix it I had to add a </p>\n\n<pre><code>using My.Other.Namespace;\n</code></pre>\n\n<p>to the top of the designer generated code file. The annoying thing was it kept getting blown away when the designer regenerated the page.</p>\n"}, {'answer_id': 9345, 'author': 'lomaxx', 'author_id': 493, 'author_profile': 'https://Stackoverflow.com/users/493', 'pm_score': 2, 'selected': False, 'text': "<p>The assembly that contains MyApp.Controls.SortableListView isn't installed in the GAC by any chance is it?</p>\n"}, {'answer_id': 9378, 'author': 'lomaxx', 'author_id': 493, 'author_profile': 'https://Stackoverflow.com/users/493', 'pm_score': 2, 'selected': False, 'text': '<p>when you added the listview, did you add it to the toolbox and then add it to the form?</p>\n'}, {'answer_id': 9387, 'author': 'Orion Edwards', 'author_id': 234, 'author_profile': 'https://Stackoverflow.com/users/234', 'pm_score': 4, 'selected': True, 'text': "<blockquote>\n  <p>when you added the listview, did you add it to the toolbox and then add it to the form?</p>\n</blockquote>\n\n<p>No, I just edited <code>Main.Designer.cs</code> and changed it from <code>System.Windows.Forms.ListView</code> to <code>MyApp.Controls.SortableListView&lt;Image&gt;</code></p>\n\n<p>Suspecting it might have been due to the generics led me to actually finding a solution.</p>\n\n<p>For each class that I need to make a SortableListView for, I defined a 'stub class' like this</p>\n\n<pre><code>class ImagesListView : SortableListView&lt;Image&gt; { }\n</code></pre>\n\n<p>Then made the <code>Main.Designer.cs</code> file refer to these stub classes instead of the <code>SortableListView</code>.</p>\n\n<p>It now works, hooray!</p>\n\n<p>Thankfully I am able to do this because all my types are known up front, and I'm only using the <code>SortableListView</code> as a method of reducing duplicate code.</p>\n"}, {'answer_id': 1293135, 'author': 'Unsliced', 'author_id': 2902, 'author_profile': 'https://Stackoverflow.com/users/2902', 'pm_score': 1, 'selected': False, 'text': '<p>I had something similar - a user control was referring to a remote serice (which I couldn\'t guarantee being available at design time). </p>\n\n<p><a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/6d3147b0-8343-44aa-a191-f0e58b96c7ea" rel="nofollow noreferrer">This post on MSDN</a> suggested that I add </p>\n\n<pre><code>if (this.DesignMode) return;\n</code></pre>\n\n<p>to the Load function of the control, or in my case to the point before the WCF client was initialised. That did the trick. </p>\n\n<p>So</p>\n\n<pre><code>private readonly Client _client = new Client();\n</code></pre>\n\n<p>becomes</p>\n\n<pre><code>private Client _client;\n\npublic new void Load()\n{\n    if(DesignMode) return;\n    _client = new Client();\n}\n</code></pre>\n'}, {'answer_id': 11748957, 'author': 'PahanCS', 'author_id': 1566944, 'author_profile': 'https://Stackoverflow.com/users/1566944', 'pm_score': 2, 'selected': False, 'text': '<p>Perhaps you forgot to add that:</p>\n\n<pre><code>    /// &lt;summary&gt;\n    /// Required designer variable.\n    /// &lt;/summary&gt;\n    private System.ComponentModel.IContainer components = null;\n\n    /// &lt;summary&gt;\n    /// Release all resources used.\n    /// &lt;/summary&gt;\n    /// &lt;param name="disposing"&gt;true if managed resources should be removed otherwise; false.&lt;/param&gt;\n    protected override void Dispose(bool disposing)\n    {\n        if (disposing &amp;&amp; (components != null))\n        {\n            components.Dispose();\n        }\n        base.Dispose(disposing);\n    }\n\n    private void InitializeComponent()\n    {\n        // ...\n        this.components = new System.ComponentModel.Container(); // Not necessarily, if You do not use\n        // ...\n    }\n</code></pre>\n'}, {'answer_id': 12206923, 'author': 'Mark Lakata', 'author_id': 364818, 'author_profile': 'https://Stackoverflow.com/users/364818', 'pm_score': 3, 'selected': False, 'text': '<p>I had this problem too, related to merging massive SVN changes (with conflicts) in the *.Designer.cs file. The solution was to just open up the design view graphically, edit a control (move it to the left then right) and resave the design. The *.Designer.cs file magically changed, and the warning went away on the next compilation.</p>\n\n<p>To be clear, you need to fix all of the code merge problems first. This is just a work around to force VS to reload them.</p>\n'}, {'answer_id': 19428824, 'author': 'cAko', 'author_id': 2890786, 'author_profile': 'https://Stackoverflow.com/users/2890786', 'pm_score': -1, 'selected': False, 'text': "<p>In my case the problem was the folder's name of my project! Why I think this:\nI use SVN and in the 'trunk\\SGIMovel' works perfectly. But in a branch folder named as 'OS#125\\SGIMovel' I can't open the designer for a form that uses a custom control and works in the trunk folder.</p>\n<p>Just get off the # and works nice.</p>\n"}, {'answer_id': 20070749, 'author': 'Nila', 'author_id': 2663777, 'author_profile': 'https://Stackoverflow.com/users/2663777', 'pm_score': 1, 'selected': False, 'text': '<p>I had the same issue. In my case this issue was due to resource initialization. I moved the following code from <code>InitializeComponent</code> method to ctor(After calling <code>InitializeComponent</code>). After that this issue was resolved:</p>\n\n<pre><code>this-&gt;resources = (gcnew System::ComponentModel::ComponentResourceManager(XXX::typeid));\n</code></pre>\n'}, {'answer_id': 33771556, 'author': 'Val', 'author_id': 681830, 'author_profile': 'https://Stackoverflow.com/users/681830', 'pm_score': 5, 'selected': False, 'text': "<p>It happened to me because of x86 / x64 architecture.</p>\n\n<p>Since Visual Studio (the development tool itself) has no x64 version, it's not possible to load x64 control into GUI designer.</p>\n\n<p>The best approach for this might be tuning GUI under x86, and compile it for x64 when necessary.</p>\n"}, {'answer_id': 42020055, 'author': 'user1027167', 'author_id': 1027167, 'author_profile': 'https://Stackoverflow.com/users/1027167', 'pm_score': 2, 'selected': False, 'text': '<p>I have had the same problem. After removing some of my own controls of the *.Designer.cs-File the problem was solved. After going back to the original code the problem still was solved. So it seems to be a problem with the Visual Sudio cache. At the moment I cannot reproduce this problem. </p>\n\n<p>If you have the problem try to emtpy the folder </p>\n\n<p>C:\\Users\\YOURNAME\\AppData\\Local\\Microsoft\\VisualStudio\\VERSION\\Designer\\ShadowCache</p>\n\n<p>Did it work?</p>\n'}]
['https://Stackoverflow.com/questions/9314', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/234/']