Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / July 2007

Tip: Looking for answers? Try searching our database.

The type or namespace name 'Collection' could not be found

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrus - 20 Jul 2007 15:16 GMT
I'm trying to compile myGeneration PropertyCollectionAll.cs  file with VCS
Express 2005 bot got error

Error 1 The type or namespace name 'Collection' could not be found (are you
missing a using directive or an assembly reference?)
PropertyCollectionAll.cs 17 39

I looked to .NET 2 help and found that Collection class is included in
mscorlib so it doen't need assembly reference.
How to fix this error ?

Whole file which causes this error is:

using System;
using System.Xml;
using System.Collections;
using System.Data;
using System.Data.OleDb;

namespace MyMeta
{

public class PropertyCollectionAll : Collection, IPropertyCollection,
IEnumerable, IEnumerator, ICollection
{

 public PropertyCollectionAll()
 {

 }

 internal void Load(IPropertyCollection local, IPropertyCollection global)
 {
  this._local  = local;
  this._global = global;
 }

 #region IPropertyCollection
   //[System.Runtime.InteropServices.DispId(0)]
 public IProperty this[string key]
 {
  get
  {
   if(this._local.ContainsKey(key))
   {
    return this._local[key];
   }
   else if(this._global.ContainsKey(key))
   {
    return this._global[key];
   }

   return null;
  }
 }

 /// <summary>
 /// This method will either add or update a key value pair.  If the key
already exists in the collection the value will be updated.
 /// If this key doesn't exist the key/value pair will be added.  If only
want to update, and not add new items, use <see cref="ContainsKey"/> to
determine if the key already exists.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public IProperty AddKeyValue(string key, string value)
 {
  throw new NotImplementedException("Cannot call AddKeyValue on this
collection");
 }

 /// <summary>
 /// Removes a key/value pair from the collection, no error is thrown if
the key doesn't exist.
 /// </summary>
 /// <param name="key">The key of the desired key/value pair</param>
 public void RemoveKey(string key)
 {
  throw new NotImplementedException("Cannot call AddKeyValue on this
collection");
 }

 /// <summary>
 /// Use ContainsKey to determine if a key exists in the collection.
 /// </summary>
 /// <param name="key">The key of the desired key/value pair</param>
 /// <returns>True if the key exists, False if not</returns>
 public bool ContainsKey(string key)
 {
  if(this._local.ContainsKey(key))
  {
   return true;
  }
  else if(this._global.ContainsKey(key))
  {
   return true;
  }

  return false;
 }

 /// <summary>
 /// Removes all key/value pairs from the collection.
 /// </summary>
 new public void Clear()
 {
  throw new NotImplementedException("Cannot call AddKeyValue on this
collection");
 }
 #endregion

 #region IEnumerable Members

 public IEnumerator GetEnumerator()
 {
  Reset();
  return (this as IEnumerator);
 }

 #endregion

 #region IEnumerator Members

 public void Reset()
 {
  useLocalEnum = true;
  wereDone = false;
  _localEnumerator  = this._local.GetEnumerator();
  _globalEnumerator = this._global.GetEnumerator();
 }

 public object Current
 {
  get
  {
   IProperty prop = null;

   if(useLocalEnum)
   {
    prop = (IProperty)_localEnumerator.Current;
   }
   else
   {
    prop = (IProperty)_globalEnumerator.Current;
   }

   return prop;
  }
 }

 public bool MoveNext()
 {
  if(this.useLocalEnum)
  {
   if(_localEnumerator.MoveNext()) return true;
  }

  if(!wereDone)
  {
   this.useLocalEnum = false;

   while(true)
   {
    if(_globalEnumerator.MoveNext())
    {
     IProperty prop = (IProperty)_globalEnumerator.Current;

     if(!this._local.ContainsKey(prop.Key))
     {
      return true;
     }
    }
    else
    {
     break;
    }
   }

   wereDone = true;
  }

  return false;
 }

 #endregion

 #region ICollection Members

 public new  bool IsSynchronized
 {
  get
  {
   // TODO:  Add Databases.IsSynchronized getter implementation
   return false;
  }
 }

 public new void CopyTo(Array array, int index)
 {
  // TODO:  Add Databases.CopyTo implementation
 }

 public new object SyncRoot
 {
  get
  {
   // TODO:  Add Databases.SyncRoot getter implementation
   return null;
  }
 }

 #endregion

 private IPropertyCollection _local;
 private IPropertyCollection _global;

 bool useLocalEnum = true;
 bool wereDone = false;
 private IEnumerator _localEnumerator = null;
 private IEnumerator _globalEnumerator = null;
}
}
Hans Kesting - 20 Jul 2007 15:47 GMT
> I'm trying to compile myGeneration PropertyCollectionAll.cs  file with
> VCS Express 2005 bot got error
[quoted text clipped - 6 lines]
> mscorlib so it doen't need assembly reference.
> How to fix this error ?

It might not need an assembly reference, but you still need to specify a
namespace: either directly or with a 'using' clause.

By the way: did you mean the Collection<>  *generic* class or the one
in Microsoft.VisualBasic?

Hans Kesting
Nicholas Paldino [.NET/C# MVP] - 20 Jul 2007 15:48 GMT
The Collection<T> class is in the System.Collections.ObjectModel
namespace, not in System.Collections.

   Also, for your implementation of IEnumerable, I would highly recommend
using yield statements to generate your iterators.  It will simplify your
code tremendously.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> I'm trying to compile myGeneration PropertyCollectionAll.cs  file with VCS
> Express 2005 bot got error
[quoted text clipped - 219 lines]
> }
> }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.