posts - 94, comments - 124, trackbacks - 82

My Links

News

View Anthony Trudeau's profile on LinkedIn

Add to Technorati Favorites

Article Categories

Archives

Post Categories

Image Galleries

Other Links

Could not find type

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.

Print | posted on Thursday, April 20, 2006 11:58 AM | Filed Under [ .NET bugs ]

Feedback

Gravatar

# re: Could not find type

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
4/20/2006 1:56 PM | Chris Falter
Gravatar

# re: Could not find type

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?
5/5/2006 11:10 AM | Marc Durham
Gravatar

# re: Could not find type

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.
5/5/2006 2:14 PM | Anthony Trudeau
Gravatar

# re: Could not find type

It's a known bug. See;
http://support.microsoft.com/kb/842706/en-us
6/13/2006 6:11 AM | Oli
Gravatar

# re: Could not find type

Thanks for the link.
6/13/2006 6:56 AM | Anthony Trudeau
Gravatar

# re: Could not find type

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.
9/11/2006 2:07 PM | Morris DeShong
Gravatar

# re: Could not find type

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.
7/11/2007 1:51 AM | Augusto Cosatti
Gravatar

# re: Could not find type

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
4/9/2008 4:32 AM | Giles
Gravatar

# re: Could not find type

Sorry - missed a step on the above post...

Before restarting, delete the bin and obj directories.
4/9/2008 4:35 AM | Giles
Gravatar

# re: Could not find type

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
4/25/2008 3:47 AM | Michael Bross
Gravatar

# re: Could not find type

Giles solution is the winner. Although I chose to only Build, as Clean was not an option.
5/17/2008 4:42 AM | Christian
Gravatar

# re: Could not find type

Thanks Giles - this was driving me nuts
7/8/2009 7:14 PM | OB1
Gravatar

# re: Could not find type

The problem is still in VS2008. It can be fixed as explained by Giles (no need to delete bin and obj though).
9/2/2009 2:04 AM | Michael
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 

Powered by: