Visual Studio 2008 having problems with namespaces when used as type in Generic coolection

Posted by patrick on Stack Overflow See other posts from Stack Overflow or by patrick
Published on 2010-05-27T16:28:20Z Indexed on 2010/05/27 18:01 UTC
Read the original article Hit count: 187

I just upgraded last week from Visual Studio 2005 to 2008. I am having an issue with compiler resolving namespaces when I use a class as a type in a Generic collection. Intellisense recognizes the class and the compiler generates no errors when I use the class except when it is a type in a Generic collection declaration either as return type for a Property or as a parameter to a method. This is happening in my only project that is targeting the 3.5 framework, but changing the project containing the class to use the 3.5 framework doesn't fix the problem.

Examples

Compile fine

  • MyClass myClass = new MyClass();
  • SortedList <DateTime,MyClass> listOfClasses = new SortedList<DateTime,MyClass>

Compile error - Namespace could not be found

  • public SortedList<DateTime,MyClass> ClassList { get; set; }

  • private void DoSomethingToLists(SortedList<DateTime,MyClass> classList)

Intellisense has no problem resolving the namespace, only the compiler. Is this a known bug or am I missing something obvious? Will SP1 fix it?

I was able to create a new library containing just this class targeting 3.5 and am now able to successfully use this in both 3.5 and 2.0 projects. My guess is that even though I tried to change the target of my original library, since it was still referencing 2.0 projects there was some conflict.

© Stack Overflow or respective owner

Related posts about visual-studio-2008

Related posts about generics