Geeks With Blogs

News

View Anthony Trudeau's profile on LinkedIn

Add to Technorati Favorites


Anthony Trudeau

I stumbled onto what I would consider a bug in the Visual Studio 2005 IDE today.  The issue came about after I rebuilt due to renaming a type that was used in a user control.  After building I got an error when I attempted to load the user control in design mode.  The error was:

Could not find type 'TypeName'. 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. 

The variable 'ControlName' is either undeclared or was never assigned. 

It turns out that I had the assembly that was being built in the IDE also in the GAC.  It needed to be in the GAC for testing that I was doing outside of the IDE.  The problem went away after I uninstalled the library from the GAC.

I understand why the problem occurs, but in my opinion Visual Studio should not perform the normal assembly resolution -- especially when the type is internal to the project like it was in this example.  Anyway, hopefully, this will help someone else out.

Posted on Thursday, April 20, 2006 11:58 AM .NET , bugs | Back to top


Comments on this post: Could not find type

# re: Could not find type
Requesting Gravatar...
Anthony,

Perhaps one of the projects in your solution links to the GAC version, rather than the project version. Let's call the linked-to assembly A and the GAC-linking project B. If C references both (project-version) A and project B, this would introduce some ambiguity as to which version of assembly A should be linked to: the project version, or the GAC version (that referenced project B refers to).
This can particularly be a problem in VB.NET when Option Strict is not on. Is that your situation?
- HTH
Left by Chris Falter on Apr 20, 2006 1:56 PM

# re: Could not find type
Requesting Gravatar...
I've just started using VS, and I'm having the same problem (I think). Could you tell me how to uninstall the library from the GAC? Or point me in the right direction?
Left by Marc Durham on May 05, 2006 11:10 AM

# re: Could not find type
Requesting Gravatar...
If you put it there you can open C:\Windows\Assembly in Windows Explorer, select the library and choose Uninstall. If an application put it there you'll have to uninstall. You can also force the assembly to load your specific DLL if you don't want to uninstall the application. That requires doing some magic in the application's configuration file.
Left by Anthony Trudeau on May 05, 2006 2:14 PM

# re: Could not find type
Requesting Gravatar...
Left by Oli on Jun 13, 2006 6:11 AM

# re: Could not find type
Requesting Gravatar...
Thanks for the link.
Left by Anthony Trudeau on Jun 13, 2006 6:56 AM

# re: Could not find type
Requesting Gravatar...
Anthony; Thanks for the post. I deleted a form a couple of times and rebuilt it thinking I was doing something wrong. Applied your solution (removed libraries from GAC) and the problem disappeared. The link from Oli is for VS 2003. Evidently the issue did not addressed in VS 2005. Thanks again, saved me alot of time.
Left by Morris DeShong on Sep 11, 2006 2:07 PM

# re: Could not find type
Requesting Gravatar...
Hello.
I also got this error message. In my case it was due to the fact that I had a form (class) within my project that had the same name as the C# project. I renamed the project and the this fixed the problem.
Left by Augusto Cosatti on Jul 11, 2007 1:51 AM

# re: Could not find type
Requesting Gravatar...
Hi,

I have also struggled with this problem on VS2005, without libraries in the GAC or a naming problem. The following worked for me:

Closing all panes (all open forms and classes) in VS2005
Save the solution and exit VS2005
Restart VS2005 and open the solution
Clean and rebuild

On the first attempt I left the forms open and it didn't work!?

Giles
Left by Giles on Apr 09, 2008 4:32 AM

# re: Could not find type
Requesting Gravatar...
Sorry - missed a step on the above post...

Before restarting, delete the bin and obj directories.
Left by Giles on Apr 09, 2008 4:35 AM

# re: Could not find type
Requesting Gravatar...
Giles solution worked for me without deleting the bin and obj directories. Thank you Giles.

Closing all panes (all open forms and classes) in VS2005
Save the solution and exit VS2005
Restart VS2005 and open the solution
Clean and rebuild
Left by Michael Bross on Apr 25, 2008 3:47 AM

# re: Could not find type
Requesting Gravatar...
Giles solution is the winner. Although I chose to only Build, as Clean was not an option.
Left by Christian on May 17, 2008 4:42 AM

# re: Could not find type
Requesting Gravatar...
Thanks Giles - this was driving me nuts
Left by OB1 on Jul 08, 2009 7:14 PM

# re: Could not find type
Requesting Gravatar...
The problem is still in VS2008. It can be fixed as explained by Giles (no need to delete bin and obj though).
Left by Michael on Sep 02, 2009 2:04 AM

# re: Could not find type
Requesting Gravatar...
And this worked for me in StudioExpress2008. Thanks Giles
Left by w on Feb 11, 2010 11:20 AM

# re: Could not find type
Requesting Gravatar...
Thanks Giles. Closing all the panes and restarting was the key. I had tried deleting the Obj and Bin folder and restarting / recompiling, but that didn't work.
Left by Josh on Aug 17, 2010 7:35 PM

# re: Could not find type
Requesting Gravatar...
All hail to the Giles! :)

VS2010 here. Self-written class extending panel, couldn't view it in Designer until using Giles solution.

Thanks man!
Left by Jan on Dec 08, 2010 9:27 AM

# re: Could not find type
Requesting Gravatar...
VS 2010 here also. Sucks the same bug is in this many versions later. This exact problem has caused much upset before finding Giles solution attached to this top-o-the-search-results article.

Working on a 30k line project with a good 20 custom controls, this problem rears its ugly and stress inducing head every week and a half. But with a solution that works, I can just handle it as part of the development process.

Thanks all of you!
Left by Wally Fortkrousty Knobthruscht on Jan 18, 2011 7:13 AM

# re: Could not find type
Requesting Gravatar...
Hi, still having this issue with vs 2008 and C#. people seem to have had luck with the above but not me. I have recently inherited this code and moved it to a new source control location. anyone have to do any extra steps that might help me? I have delted all BIN and OBJ in my sub project directories but no luck.
Left by Mike on Mar 25, 2011 11:52 AM

# re: Could not find type
Requesting Gravatar...
""The problem went away after I uninstalled the library from the GAC.""

How can we do this ?
Left by Zil-e-Huma on Nov 12, 2011 3:56 PM

# re: Could not find type
Requesting Gravatar...
For just a mucked up usercontrol designer error (no GAC involvement) I opened the usercontrol's resource window, ie double-clicking the .resx file, closed it, then when I switched back to the control's designer window, I saw the error page going away! Odd.
Left by stentor on Jan 18, 2012 12:30 PM

# re: Could not find type
Requesting Gravatar...
VS 2012 Professional ran into this problem. Thanks Giles for the work around. It is amazing that this is still a problem so many years later.
Left by Brandon on Aug 08, 2013 10:11 AM

Your comment:
 (will show your gravatar)


Copyright © Anthony Trudeau | Powered by: GeeksWithBlogs.net